Skip to content

Instantly share code, notes, and snippets.

@iamtrk
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamtrk/10550573 to your computer and use it in GitHub Desktop.
Save iamtrk/10550573 to your computer and use it in GitHub Desktop.
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