A detailed description of the C3P0 configuration file in the JDBC Connection pool and how to use it in Java

Source: Internet
Author: User
Tags cdata mysql login

<c3p0-config>
<!--default configuration, if not specified, use this configuration--
<default-config>
<property name= "Driverclass" >com.mysql.jdbc.Driver</property>
<property name= "Jdbcurl" >
<! [cdata[jdbc:mysql://127.0.0.1:3306/hncu?useunicode=true&characterencoding=utf-8]]>
</property>
<property name= "User" >root</property>
<property name= "Password" >1234</property>
<!--Initialize Pool size--
<property name= "Initialpoolsize" >2</property>
<!--maximum idle time-
<property name= "MaxIdleTime" >30</property>
<!--maximum number of connections--
<property name= "Maxpoolsize" >10</property>
<!--at least several connections--
<property name= "Minpoolsize" >2</property>
<!--How many batch statements can be executed at a time--
<property name= "Maxstatements" >50</property>
</default-config>
<!--named Configuration--
<named-config name= "Hncu" ><!--here is the name of the Setup profile--
<property name= "Driverclass" >com.mysql.jdbc.Driver</property>
<property name= "Jdbcurl" >
<! [cdata[jdbc:mysql://127.0.0.1:3306/hncu?useunicode=true&characterencoding=utf-8]]><!--This setting is <! [cdata[...] The output is not parsed--
</property>
<property name= "user" >root</property><!--mysql login name--
<property name= "Password" >1234</property><!--if no password can be set to <property name= "password" ></ Property>-->
<property name= "Acquireincrement" >5</property><!--if the data in the pool is not connected enough, how many times it grows
<property name= "Initialpoolsize" >10</property>
<property name= "Minpoolsize" >5</property>
<property name= "Maxpoolsize" >15</property>
<property name= "Maxstatements" >0</property>
<property name= "Maxstatementsperconnection" >5</property> <!--He's important, but there ' s only one of him -
</named-config>
</c3p0-config>
--------------------------------------------------------------------------------------------------------------- ----------------------------

Import Com.mchange.v2.c3p0.ComboPooledDataSource;

Combopooleddatasource pool=new Combopooleddatasource ();
System.out.println (Pool.getproperties ());//the user name and password of MySQL can be exported here;
for (int i=0;i<15;i++) {
Connection con=pool.getconnection ();
System.out.println (Con.hashcode ());//This is the address of the output connection.
}

A detailed description of the C3P0 configuration file in the JDBC Connection pool and how to use it in Java

Related Article

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.