Configuring C3P0 data Sources in the Applicationcontext.xml file in the spring framework

Source: Internet
Author: User

This is an example I have seen on the internet before, I think c3p0 more mature, stable, in the general project to choose C3P0 to do database connection pool is better, so I posted in the Applicationcontext.xml file to configure an example of C3P0, for reference.

<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" > <property Name= "Driverclass" > <value>com.mysql.jdbc.Driver</value> </property> <property name= " Jdbcurl "> <value>jdbc:mysql://localhost:3306/test</value> </property> <property name=" user "> <value>root</value> </property> <property name=" password "> <value>123456</ Value> </property> <!--the minimum number of connections retained in the connection pool. --> <property name= "minpoolsize" > <value>5</value> </property> <!--The maximum number of connections retained in the connection pool. Default:15--> <property name= "maxpoolsize" > <value>30</value> </property> <!-- The number of connections to be fetched at initialization time between Minpoolsize and Maxpoolsize. Default:3--> <property name= "initialpoolsize" > <value>10</value> </property> <!-- Maximum idle time, not used within 60 seconds, the connection is discarded. If 0, it will never be discarded. default:0--> <property name= "MaxIdleTime" > <value>60</value> </proPerty> <!--The number of simultaneous connections c3p0 one at a time when connections in the connection pool are depleted. Default:3--> <property name= "acquireincrement" > <value>5</value> </property> <!-- Standard parameters for JDBC to control the number of preparedstatements loaded in the data source. However, because the cached statements belong to a single connection instead of the entire connection pool. 
So setting this parameter takes into account many factors. If both maxstatements and maxstatementsperconnection are 0, the cache is closed. default:0--> <property name= "maxstatements" > <value>0</value> </property> <!-- Check for free connections in all connection pools every 60 seconds.

default:0--> <property name= "Idleconnectiontestperiod" > <value>60</value> </property> <!--defines the number of repeated attempts after a new connection has been failed to get from the database. default:30--> <property name= "acquireretryattempts" > <value>30</value> </property> <! --Getting a connection failure will cause all threads waiting to connect to get the connection to throw an exception. However, the data source remains valid and continues to attempt to get the connection the next time you call Getconnection (). If set to True, the data source will be declared disconnected and permanently closed after the attempt to acquire the connection fails. Default:false--> <property name= "Breakafteracquirefailure" > <value>true</value> </property > <!--because of the high performance, please use it only when you need it. If set to true then in each connection commits the Time is officers transferred Guevara to check its validity. It is recommended that you use methods such as Idleconnectiontestperiod or automatictesttable to improve the performance of your connection tests. Default:false--> <property name= "Testconnectiononcheckout" > <value>false</value> </ Property> </bean>


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.