2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to establish a connection pool in JDBC?

Can anybody explain how to establish a JDBC connection pool?
userimage
If you need a standalone connection pool, my preference goest to C3P0 over DBCP  I just had too much problems with DBCP under heavy load.

ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "org.postgresql.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:postgresql://localhost/mysqldb" );
cpds.setUser("pankaj");
cpds.setPassword("pk_password")
;

// the settings below are optional -- c3p0 can work with defaults
cpds.setMinPoolSize(5);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(20);
Answer is