Several important classes and interfaces of spring

Source: Internet
Author: User

The 1.datasource interface is the interface under the Javax.sql package, not spring, which is the javax.sql

The DataSource interface has an important method getconnection () method

Connection getconnection (string Username, string password) throws SQLException;

Those spring-supported database connection pools are implemented with the DataSource interface

For example, the following is Ali's Druiddatasource database connection pool source code, it is the implementation of the DataSource Getconnection () method

As long as it is a class that implements this method, it can be the datasource of spring.

@Override Publicdruidpooledconnection getconnection () throws SQLException {returngetconnection (maxwait); }     PublicDruidpooledconnection getconnection (LongMaxwaitmillis) throws SQLException {init (); if(Filters.size () >0) {Filterchainimpl Filterchain=NewFilterchainimpl ( This); returnFilterchain.datasource_connect ( This, Maxwaitmillis); } Else {            returnGetconnectiondirect (Maxwaitmillis); }    }

2.jdbcTemplate is the tool of spring, under the Springframework.jdbc bag

3. So spring if you want, you can also connect to the database itself, to execute SQL statements, not mybatis or hibernate.

Just use spring's own jdbctemplate, but there's no ORM match.

4. If you want to use MyBatis, hibernate them to connect to the database, it is necessary to use their similar jdbctemplate ah, such as MyBatis sqlsessiontemplate.

5. So in spring, to manipulate the database is divided into three steps: 1. Database, DataSource 2. Find a sharp weapon to manipulate the SQL language, JdbcTemplate or Sqlsessionfactory 3. Inject a sharp weapon into the spring IOC container

The core of 6.1.spring integrated MyBatis is Sqlsessionfactorybean, Mapperfactorybean (Single interface)

The core of 7.1.spring integrated MyBatis is Sqlsessionfactorybean, Mapperfactorybean (Single interface)

The core of 8.1.spring integrated MyBatis is Sqlsessionfactorybean, Mapperfactorybean (Single interface)

Several important classes and interfaces of spring

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.