Jdbctemplete class Hierarchy
- JdbcAccessor: To manage and configure the DataSource data source;
- JdbcOperations: Defines the basic operation method of database operation through JDBC;
- JdbcTemplate: Provides the details of implementing the JdbcOperations interface method;
Template method design pattern in JdbcTemplate design mode: The basic skeleton of the algorithm is defined in the template method, some details of which are implemented by subclasses. When JDBC accesses a database, it needs to create and maintain, destroy connection, Statement, and handle SqlException, and so on, as follows:
As can be seen from the above, all database operations have a fixed routine, in order to avoid duplication of code,JdbcTemplate uses the template method design pattern to place the invariant parts involved in database accessJdbcTemplate, and the changing parts (such as SQL statements) are placed in the callback;JdbcTemplate in the
Execute ()It is
Template Method:
From the code above, you can see that creating connection and statement, and handling exception, freeing resources, and so on, are fixed, and the specific SQL is a changing part, all in callback. The following is an example of query: The following is an example of an update: JdbcTemplate in the callback there are 3 main:
- Statement;
- CallableStatement;
- PreparedStatement;
Each statement has its own corresponding execute () method, all of which are template methods, and the implementation details are basically the same;
The callback function in each of the Execute () methods corresponds to the above 3 types respectively;
JdbcTemplate's query ()
The Query method in JdbcTemplate is basically used PreparedStatement
JdbcTemplate Method Overview
The query method is divided into the following major categories:
- Query ()
- queryForList ()
- queryForMap ()
- queryForMap ()
- queryForRowSet ()
And each of the above, basically can be divided into 3 categories, respectively:
- Resultsetextractor<t>:
- RowCallbackHandler
- Rowmapper<t>
Specific differences can be found in: http://www.cnblogs.com/ssslinppp/p/4954099.html
From for notes (Wiz)
"Jdbctemplete" Jdbctemplete Code Details--A detailed description of the template method