DBCP and C3P0 use--not perfect

Source: Internet
Author: User

First, preface:

Both DBCP and C3PO can be used as data connection pools,

Second, import jar package:

Third, configuration Applicationcontext.xml file

Configure DBCP

<!--Create a data source -    <BeanID= "DataSourceId"class= "Org.apache.commons.dbcp.BasicDataSource">        < Propertyname= "Driverclassname"value= "Com.mysql.jdbc.Driver"></ Property>        < Propertyname= "url"value= "Jdbc:mysql://localhost:3306/ee19_spring_day02"></ Property>        < Propertyname= "username"value= "root"></ Property>        < Propertyname= "Password"value= "1234"></ Property>    </Bean>    <!--to create a template, you need to inject a data source -    <BeanID= "Jdbctemplateid"class= "Org.springframework.jdbc.core.JdbcTemplate">        < Propertyname= "DataSource"ref= "DataSourceId"></ Property>    </Bean>        <!--Configure DAO -    <BeanID= "Userdaoid"class= "com.itheima.c_dbcp." Userdao ">        < Propertyname= "JdbcTemplate"ref= "Jdbctemplateid"></ Property>    </Bean>

Configure C3P0

<!--Create a data source c3p0 -    <BeanID= "DataSourceId"class= "Com.mchange.v2.c3p0.ComboPooledDataSource">        < Propertyname= "Driverclass"value= "Com.mysql.jdbc.Driver"></ Property>        < Propertyname= "Jdbcurl"value= "Jdbc:mysql://localhost:3306/ee19_spring_day02"></ Property>        < Propertyname= "User"value= "root"></ Property>        < Propertyname= "Password"value= "1234"></ Property>    </Bean>

Using Jdbcdaosupport

Spring configuration file
    <!--Configure DAO * DAO to inherit Jdbcdaosupport, then only need to inject the data source, the underlying will automatically create the template -    <BeanID= "Userdaoid"class= "Com.itheima.e_jdbcdaosupport." Userdao ">        < Propertyname= "DataSource"ref= "DataSourceId"></ Property>    </Bean>

DBCP and C3P0 use--not perfect

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.