Skip to content

Instantly share code, notes, and snippets.

@iamtrk

iamtrk/ConnectionPool.java

Last active Aug 29, 2015
Embed
What would you like to do?
JDBC Connection pool implemented in C3PO.
public class ConnectionPool {
private ComboPooledDataSource cpds;
private static ConnectionPool datasource;
private ConnectionPool() throws IOException, SQLException ,PropertyVetoException{
cpds = new ComboPooledDataSource();
cpds.setJdbcUrl("jdbc:mysql://localhost:3306/data_base");
cpds.setUser("usr");
cpds.setPassword("pwd");
cpds.setDriverClass("com.mysql.jdbc.Driver");
cpds.setInitialPoolSize(7);
cpds.setAcquireIncrement(15);
cpds.setMaxPoolSize(1000);
cpds.setMinPoolSize(3);
cpds.setMaxStatements(10);
cpds.setIdleConnectionTestPeriod(2000);
}
public static ConnectionPool getInstance() throws IOException, SQLException,PropertyVetoException {
if(datasource == null){
synchronized (ConnectionPool.class) {
if(datasource == null){
datasource = new ConnectionPool();
}
}
}
return datasource;
}
public Connection getConnection() throws SQLException {
return this.cpds.getConnection();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment