This is the central class in the JDBC core package. It simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. This class executes SQL queries or updates, initiating iteration over ResultSets and catching JDBC exceptions and translating them to the generic, more informative exception hierarchy defined in the
org.springframework.dao
package.
Code using this class need only implement callback interfaces, giving them a clearly defined contract. The {@link PreparedStatementCreator} callbackinterface creates a prepared statement given a Connection, providing SQL and any necessary parameters. The {@link ResultSetExtractor} interface extractsvalues from a ResultSet. See also {@link PreparedStatementSetter} and{@link RowMapper} for two popular alternative callback interfaces.
Can be used within a service implementation via direct instantiation with a DataSource reference, or get prepared in an application context and given to services as bean reference. Note: The DataSource should always be configured as a bean in the application context, in the first case given to the service directly, in the second case to the prepared template.
Because this class is parameterizable by the callback interfaces and the {@link org.springframework.jdbc.support.SQLExceptionTranslator}interface, there should be no need to subclass it.
All SQL operations performed by this class are logged at debug level, using "org.springframework.jdbc.core.JdbcTemplate" as log category.
@author Rod Johnson
@author Juergen Hoeller
@author Thomas Risberg
@since May 3, 2001
@see PreparedStatementCreator
@see PreparedStatementSetter
@see CallableStatementCreator
@see PreparedStatementCallback
@see CallableStatementCallback
@see ResultSetExtractor
@see RowCallbackHandler
@see RowMapper
@see org.springframework.jdbc.support.SQLExceptionTranslator