The data access layer is responsible for managing the database connection, retrieving data from the database, and storing data back to the database. Unit testing the data access layer is very important; if anything goes wrong in this layer, the application will fail. We can unit test the data access logic in isolation from the database and perform integration testing to verify the application and database integrity.
We'll use the Derby database to store real user data. We'll create a utility class to create a database, derbyDB
, and create a table with details such as user_data
(userId varchar(50)
, password varchar(50)
, fname varchar(40)
, and lname varchar(40)
). Skipping the class details for brevity, you can download the class from the Packt Publishing site. The class name is DatabaseManager
and the package is com.packt.dao
under the src
source package.
The following are the steps to build the Spring DAO layer:
Modify the
beans.xml
file to define a data-source...