In the previous section, we have seen the shortcomings of using the JDBC API as a low-level data access API for implementing the DAOs. These shortcomings are as follows:
close()
method. This is a risky plan because a novice programmer might very easily skip some of the code fragments. As a result, the resources would run out and bring the system to a stop.SQLException
, since the JDBC drivers report all the errors suitable by raising SQLException
. It is not possible to recover these exceptions. Moreover, the message and the error code obtained from the SQLException
object are database vendor-specific, so it is difficult to write a portable DAO error messaging code.To solve the aforementioned problems, we need to identify the parts of the code that are fixed and then encapsulate them into some reusable objects. The Spring Framework provides a solution for these problems by giving a thin, robust, and highly extensible JDBC abstraction framework.
The JDBC abstraction framework provided under the Spring Framework is considered to be a value-added service that takes care of all the low-level details, such as retrieving connection, preparing the statement object, executing the query, and releasing the database resources. While using it for data access, the application developer needs to specify the SQL statement for executing and retrieving the result.
To handle the different aspects of JDBC, Spring JDBC is divided into packages, as shown in the following table: