Simplifying persistence with Spring

Look at the PhoneBookDerbyDao class. It has 398 lines to support create, read, update, and delete (CRUD) operations. Every method performs almost similar tasks. The following tasks are invoked from the CRUD methods:

  • Passing connection parameters
  • Opening a connection
  • Creating a statement
  • Preparing the statement
  • Executing the statement
  • Iterating through the results (only in the read method)
  • Populating the model objects (only in the read method)
  • Processing any exception
  • Handling transactions
  • Closing the ResultSet (only in the read method)
  • Closing the statement
  • Closing the connection

The Spring framework provides APIs to reduce JDBC code duplication. Spring JDBC hides the low-level details and allows us to concentrate on business ...

Get Mastering Unit Testing Using Mockito and JUnit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.