"Jdbctemplete" Jdbctemplete Code Details--A detailed description of the template method

Source: Internet
Author: User


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:
    1. Statement;
    2. CallableStatement;
    3. 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:
    1. Resultsetextractor<t>:
    2. RowCallbackHandler
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.