1,配置文件!
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/MySQL</property>//对应数据库自己改
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="user">root</property>
<property name="password">123456</property>//密码自己改
<property name="acquireIncrement">3</property>//每次增长多少
<property name="initialPoolSize">5</property>//初始化多少
<property name="minPoolSize">2</property>//最小连接数
<property name="maxPoolSize">8</property>//最大连接数
</default-config>
</c3p0-config>
2,JAVA代码,数据库连接架包自己接
public class getConnection {
public Connection connection(){
ComboPooledDataSource cps = new ComboPooledDataSource();
Connection connection = null;
try {
connection = cps.getConnection();
return connection;
} catch (SQLException e) {
System.out.println("连接池获取失败!!!");
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
System.out.println(new getConnection().connection());
}
}