导入jar包
代码
package com.jp;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.beans.PropertyVetoException;
import java.sql.SQLException;
/**
* @program: Test01
* @description: c3p0数据库连接池使用
* @author: CoderPengJiang
* @create: 2019-12-19 22:09
**/
public class C3P0Test {
public static void main(String[] args) throws PropertyVetoException, SQLException {
//核心类
ComboPooledDataSource dataSource=new ComboPooledDataSource();
//基本的四项设置
dataSource.setDriverClass("com.mysql.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://192.168.127.128:3306/blog");
dataSource.setUser("root");
dataSource.setPassword("201314");
//其他设置
//初始化连接数为10
dataSource.setInitialPoolSize(10);
//设置最大的连接数为20
dataSource.setMaxPoolSize(20);
//设置最小的连接数
dataSource.setMinPoolSize(3);
//设置每次创建的连接数
dataSource.setAcquireIncrement(3);
System.out.println(dataSource.getConnection());
}
}
输出