What are the different approaches for JDBC database access in Spring?

Answered

What are the different approaches for JDBC database access in Spring?

Ninja Asked on 19th September 2018 in Spring DAO.
Add Comment
1 Answer(s)
Best answer

There are several approaches for JDBC database access in Spring and they are:

    • JdbcTemplate is the classic Spring JDBC approach and the most popular. This “lowest level” approach and all others use a JdbcTemplate under the covers.
    • 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.
    • 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.
Ninja Answered on 19th September 2018.
Add Comment