Flynn, local librarian, wants to digitalize his good ol' book register. Searching for records in a massive set of massive books is time consuming. Your task is to create a simple application that will store books and authors in a PostgreSQL database, and will allow Flynn to add, update, and list all entries.
- connect to a database using low level technology (JDBC).
- handle edge cases and exceptions.
-
Create a PostgreSQL database called
books
and import both schema and data frombooks.sql
file.- Database with name
books
exists - Tables
book
andauthor
are created and filled with sample data
- Database with name
-
Create a class called
BookDbManager
(in a subpackage calledmanager
) with a methodconnect()
that will link to yourbooks
database and returnDataSource
. UsePGSimpleDataSource
to establish connection.- Class
BookDbManager
exists, and itsconnect()
method connects to the database and returns aDataSource
.
- Class
-
Create
AuthorDaoJdbc
andBookDaoJdbc
classes in themodel
subpackage. Each one of them must accept aDataSource
as a constructor parameter. Instances of JDBC DAOs will be managed byBookDbManager
.- Classes
AuthorDaoJdbc
andBookDaoJdbc
are implemented. - Classes
AuthorDaoJdbc
andBookDaoJdbc
usePreparedStatement
s. - Exceptions are chained and thrown as RuntimeExceptions, to avoid "exception swallowing".
- Classes
-
Make this app functional with a simple console UI. Implement
UserInterface
's methods, and call them fromBookDbManager
using a main menu -> submenu workflow. Make sure that the user is able to list and edit all the records, as well as add new ones.- Main menu with options
a - Authors
,b - Books
andq - Quit
navigates to the selected submenu and is functional - Resources menu with options
l - List
,a - Add
,e - Edit
andq - Quit
is functional on the selected entities
- Main menu with options
None
- When you create a
dataSource
object that will be responsible for your connection to the database, remember to check whether the connection actually works. You can do it by invokingdataSource.getConnection().close();
- Remember to keep your queries SQL-injection-proof by using
java.sql.PreparedStatement