c3p0 use steps

// 1, even c3p0 introduced packets, and driver package mysql 

// 2, the configuration profile c3p0.xml
<-config the c3p0> <-! read using the default configuration connection pool object -> <default-config> <-! connection parameter -> <Property name = "driverClass" > com.mysql.jdbc.Driver </ Property> <Property name = "the jdbcUrl" > JDBC: MySQL: // localhost: 3306 / eStore </ Property> <Property name = "User" > the root </ Property> <Property name = "password" > 123 < / Property> <-! connection pool parameters -> <Property name = "initialPoolSize" >. 5 </ Property> <property name="maxPoolSize">10</property> <property 











name="checkoutTimeout">3000</property>
</default-config>

<named-config name="otherc3p0">
<!-- 连接参数 -->
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/estore</property>
<property name="user">root</property>
<property name="password">123</property>

<!-- 连接池参数 -->
<property name="initialPoolSize">5</property>
<property name="maxPoolSize">8</property>
<property name="checkoutTimeout">1000</property>
</named-config>
</c3p0-config>


//3、代码测试
package cn.itcast.datasoure.c3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
* @author newcityman
* @date 2019/8/16 - 21:45
*/
public class C3P0Demo01 {
public static void main(String[] args) {
Conn = Connection null;
the try {
//. 1, create a database connection pool object
the DataSource = DS new new ComboPooledDataSource () ;
// 2, obtaining the connection object
Conn ds.getConnection = () ;
. The System Out.println (Conn) ;
} the catch (SQLException E) {
e.printStackTrace () ;
}
}
}

Guess you like

Origin www.cnblogs.com/newcityboy/p/11366808.html