C3P0连接池
来源:互联网 发布:户外广告牌生成软件 编辑:程序博客网 时间:2024/05/16 10:31
package C3P0;
import java.sql.Connection;
import java.sql.SQLException;
import java.beans.PropertyVetoException;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class DBPool{
private static DBPool dbPool;
private ComboPooledDataSource dataSource;
static {
dbPool=new DBPool();
}
public DBPool(){
try {
dataSource=new ComboPooledDataSource();
dataSource.setUser( "id ");
dataSource.setPassword( "pw ");
dataSource.setJdbcUrl( "jdbc:mysql://127.0.0.1:3306/test?
autoReconnect=true&useUnicode=true&characterEncoding=GB2312 ");
dataSource.setDriverClass( "com.mysql.jdbc.Driver ");
dataSource.setInitialPoolSize(2);
dataSource.setMinPoolSize(1);
dataSource.setMaxPoolSize(10);
dataSource.setMaxStatements(50);
dataSource.setMaxIdleTime(60);
} catch (PropertyVetoException e) {
throw new RuntimeException(e);
}
}
public final static DBPool getInstance(){
return dbPool;
}
public final Connection getConnection() {
import
import
import
import
public
autoReconnect=true&useUnicode=true&characterEncoding=GB2312 ");