This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 6.2.1! |
Choosing an Approach for JDBC Database Access
You can choose among several approaches to form the basis for your JDBC database access.
In addition to three flavors of JdbcTemplate
, a SimpleJdbcInsert
and SimpleJdbcCall
approach optimizes database metadata, and the RDBMS Object style results in a more
object-oriented approach. Once you start using one of these approaches, you can still mix
and match to include a feature from a different approach.
-
JdbcTemplate
is the classic and most popular Spring JDBC approach. This “lowest-level” approach and all others use aJdbcTemplate
under the covers. -
NamedParameterJdbcTemplate
wraps aJdbcTemplate
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. -
SimpleJdbcInsert
andSimpleJdbcCall
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 a map of parameters matching the column names. This works only if the database provides adequate metadata. If the database does not provide this metadata, you have to provide explicit configuration of the parameters. -
RDBMS objects — including
MappingSqlQuery
,SqlUpdate
, andStoredProcedure
— require you to create reusable and thread-safe objects during initialization of your data-access layer. This approach allows you to define your query string, declare parameters, and compile the query. Once you do that,execute(…)
,update(…)
, andfindObject(…)
methods can be called multiple times with various parameter values.