C3p0 creates a connection pool,

Source: Internet
Author: User

C3p0 creates a connection pool,
C3p0 is currently the most widely used database connection pool

Feature: the auto-collect connection feature is available;

Asynchronous execution is available.

Use c3p0 to export packages, link https://sourceforge.net/projects/c3p0/

Package to be imported: c3p0-0.9.5.2-sources.jar mchange-commons-java-0.2.11-sources.jar

Detailed usage of the c3p0 decompression package under doc (all in English)

Core class: ComboPooledDataSource

Profile: Must be called c3p0-config.xml

Java code:

Public class C3p0 {

Private static ComboPooledDataSource ds = null;

// Static code block

Static {

Ds = new ComboPooledDataSource ();

}

Public static Connection getConnection (){

Try {

// Get a Connection object through ds
Return ds. getConnection ();
} Catch (SQLException e ){
E. printStackTrace ();
}
Return null;

}

  

Public static void main (String [] args ){
For (int I = 0; I <5; I ++ ){

// Output the connection in the console
System. out. println (getCon ());
}
}

}

Configuration file:

<C3p0-config>
<! -- Default configuration -->
<Default-config>
<Property name = "jdbcUrl"> jdbc: mysql: // localhost: 3306/test </property>
<Property name = "user"> root </property>

<Property name = "password"> 123123 </property>

<! -- Database-driven -->
<Property name = "driverClass"> com. mysql. jdbc. Driver </property>

<! -- Initialization value in connection pool -->
<Property name = "initialPoolSize"> 5 </property>

<! -- Maximum value in connection pool -->
<Property name = "maxPoolSize"> 10 </property>

<! -- Exceeds the maximum wait time -->
<Property name = "checkoutTimeout"> 3000 </property>
</Default-config>

<! -- Configure by name intergalactoApp -->
<Named-config name = "intergalactoApp">
<Property name = "jdbcUrl"> jdbc: mysql: // localhost: 3306/test </property>
<Property name = "user"> root </property>
<Property name = "password"> 123123 </property>
<Property name = "driverClass"> com. mysql. jdbc. Driver </property>
<Property name = "initialPoolSize"> 10 </property>
<Property name = "maxPoolSize"> 20 </property>
<Property name = "checkoutTimeout"> 5000 </property>
</Named-config>
C3p0-config>

 

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.