Saturday, February 7, 2009

Connection pool using apache commons-dbcp

You can create java connection pooling using commons-dbcp-all-1.3.jar or commons-dbcp.jar
The Code is given,

BasicDataSource basicDataSource = new BasicDataSource();
//oracle.jdbc.driver.OracleDriver -- for oracle
//com.mysql.jdbc.Driver -- for mysql
basicDataSource.setDriverClassName(properties.getProperty(driverclassname);//
basicDataSource.setDefaultAutoCommit(false);
basicDataSource.setMaxActive(5);
basicDataSource.setUrl(properties.getProperty(serverurl);
basicDataSource.setUsername(properties.getProperty("username));
basicDataSource.setPassword(properties.getProperty("password));
basicDataSource.setMaxIdle(2);
//basicDataSource.setMaxWait(1000);
basicDataSource.setRemoveAbandoned(true);
basicDataSource.setRemoveAbandonedTimeout(3);

No comments: