Last active
August 29, 2015 13:59
-
-
Save iamtrk/10550573 to your computer and use it in GitHub Desktop.
JDBC Connection pool implemented in C3PO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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