Spring's C3P0 Connection pool configuration and usage

Source: Internet
Author: User

1. Import Package: C3P0 and Mchange Package

2, the Code implementation method:

1  PackageHelloworld.pools;2 3 ImportCom.mchange.v2.c3p0.ComboPooledDataSource;4 Importorg.springframework.jdbc.core.JdbcTemplate;5 Importjava.beans.PropertyVetoException;6 7 /**8 * C3P0 Connection Pool Usage Method-code9 * Import Package: C3P0 and Mchange packageTen  */ One  Public classC3p0codeimpl { A      Public Static voidMain (string[] args) { -Combopooleddatasource DataSource =NewCombopooleddatasource (); -         Try { theDatasource.setdriverclass ("Com.mysql.jdbc.Driver"); -Datasource.setjdbcurl ("Jdbc:mysql://10.15.1.200:3306/gxrdb"); -Datasource.setuser ("root"); -Datasource.setpassword ("root"); +}Catch(propertyvetoexception e) { - e.printstacktrace (); +         } A  at         //set up a data source -JdbcTemplate JdbcTemplate =NewJdbcTemplate (dataSource); -  - //invoke a method in the JdbcTemplate object to implement the Operation -String sql = "INSERT into user value (?,?,?)"; -         //table structure: ID (int, self-increment), name (varchar), age (int) in         introws = jdbctemplate.update (sql,NULL, "Tom2", 25); -System.out.println ("Insert line number:" +rows); to     } +}

3. How to implement spring configuration

Beans.xml

1 <Beansxmlns= "Http://www.springframework.org/schema/beans"2 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"3 xmlns:contexnt= "Http://www.springframework.org/schema/context"4 xsi:schemalocation= "Http://www.springframework.org/schema/beans5 http://www.springframework.org/schema/beans/spring-beans.xsd6 Http://www.springframework.org/schema/context7 http://www.springframework.org/schema/context/spring-context-2.5.xsd ">8 9     <!--Configuring the C3P0 connection pool -Ten     <BeanID= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource"> One         <!--Injection Properties - A         < Propertyname= "Driverclass"value= "Com.mysql.jdbc.Driver"></ Property> -         < Propertyname= "Jdbcurl"value= "Jdbc:mysql://10.15.1.200:3306/gxrdb"></ Property> -         < Propertyname= "User"value= "root"></ Property> the         < Propertyname= "Password"value= "root"></ Property> -     </Bean> -  -  + </Beans>

Spring's C3P0 Connection pool configuration and usage

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.