Spring JDBC is a part of Data access layer provided by Spring. The Spring Framework takes care of all the low-level details that can make JDBC such a tedious API to develop with such as database connections, creating prepare statements, process exceptions etc.,
Spring JDBC is a part of Data access layer provided by Spring. The Spring Framework takes care of all the low-level details that can make jdbc such a tedious API to develop with such as database connections, creating prepare statements, process exceptions etc.,
The following are the approaches to form the basis of JDBC database access.
JdbcTemplate
is the classic Spring JDBC approach and the most popular. This "lowest level" approach and all others use a JdbcTemplate under the covers, and all are updated with Java 5 support such as generics and varargs.
NamedParameterJdbcTemplate
wraps a JdbcTemplate
to provide named parameters instead of the traditional JDBC ?
placeholders. This approach provides better documentation and ease of use when you have multiple parameters for an SQL statement.
SimpleJdbcTemplate
combines the most frequently used operations of JdbcTemplate
and NamedParameterJdbcTemplate
.
SimpleJdbcInsert
and SimpleJdbcCall
optimize database metadata to limit the amount of necessary configuration. This approach simplifies coding so that you only need to provide the name of the table or procedure and provide a map of parameters matching the column names. This only works if the database provides adequate metadata. If the database doesn't provide this metadata, you will have to provide explicit configuration of the parameters.
RDBMS Objects including MappingSqlQuery
, SqlUpdate
and StoredProcedure
requires you to create reusable and thread-safe objects during initialization of your data access layer. This approach is modeled after JDO Query wherein you define your query string, declare parameters, and compile the query. Once you do that, execute methods can be called multiple times with various parameter values passed in.