The spring JDBC is a type of data access technology. This technology is used for accessing data from database. The spring DAO (Data access object) make it easy for using this technology. There are lot of examples listed here. By using this technology we can reduce a lot of overhead and also we don’t need to worry about Exception handling that is related to each technology. JDBC provide some actions and responsibilities. Some responsibilities are taken by developers and others are taken by Spring itself.
The developer’s responsibilities are
The responsibilities of Spring are
The spring framework JDBC consists of four types of packages.
The org.springframework.jdbc.core package includes
The org.springframework.jdbc.datasource package includes,
a) A utility class
Utility classes are used for easy DataSource access. This class provides static methods to obtain connections from JNDI and to close connections if necessary. It permits the thread bound connections. E.g.:- Use of DataSourceTransactionManager.
b) Different simple DataSource
Simple DataSource implements help for testing and running unmodified JDBC code outside of a J2EE container.
The org.springframework.jdbc.object package includes,
Several classes that represent RDBMS queries, updates, and stored procedures as thread safe, reusable objects. This approach is modeled by JDO, although objects returned by queries are “disconnected” from the database.
The org.springframework.jdbc.support package is helps to find SQLException translation functionality and some utility classes.
We are using different approaches for database access.
In the JDBC core package the JdbcTemplate class is the central class. It handles the creation and release of resources. This helps to
The JdbcTemplate can be applied within a DAO implementation via direct instantiation with a DataSource reference, or be configured in a spring IOC container and given to DAOs as a bean reference.
int rowCount = this.jdbcTemplate.queryForInt("select count(0) from t_accrual");