Category Archives: apache-commons-dbcp

DataSource.setConnectionProperties returning null even after setting them

I'm getting a DataSource by DataSource ds1 = (DataSource)ctx.lookup("java:/comp/env/jdbc/UserDatabase"); There is a context.xml file through which this datasource object is fetched. But the problem is that I get a property of DataSource named "connectionProperties" as NULL inititally. But then I set that property manually in my program by this : ds1.setConnectionProperties(connectionProperties.toString()); The statement is executed by still I get "connectionProperties" as NULL only. Please help.

How to store password in encrypted form in Apache DBCP BasicDataSource?

I am using Apache DBCP2 along with spring for JDBC connection pool. The org.apache.commons.dbcp.BasicDataSource class stores password in plain text. When I took memory snapshot of the java process using java profiler, the database password was visible as plain text in value of password attribute of BasicDataSource class instances. How can we store password in encrypted form in memory when using BasicDataSource in DBCP ? I have managed to store password in encrypted format on disk and decrypt it just before creating the instances of BasicDataSource. However finally when the BasicDataSource objects are created in memory, they display password as plain text which can be easily found out by taking memory snapshot of the process.

Apache-Commons-DBCP Issue

java.lang.Object.wait(Native Method) 
java.lang.Object.wait(Object.java:485) 
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:810) 
org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:180) 
java.sql.DriverManager.getConnection(DriverManager.java:582) 
java.sql.DriverManager.getConnection(DriverManager.java:207) 

The application becomes unresponsive in production server.

verified that the connection are closed properly in finally block. What are the probable scenarios for this situation

DBCP connection hung

I am seeing following in the thread dump from load environment. I can see lot of connection available on the database side but still the queries are hung because of below wait. Any Idea if this is an issue with dpcp?

Jar Version : commons-dbcp-1.4.jar, commons-pool-1.5.3.jar and Jboss 7.1 server

<bean id="datasource1" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value=""/>
    <property name="username" value="" />
    <property name="password" value="" />
    <property name="poolPreparedStatements" value="false" />
    <property name="removeAbandoned" value="true" />
    <property name="logAbandoned" value="true" />
    <property name="validationQuery" value="SELECT 1" />
    <property name="timeBetweenEvictionRunsMillis" value="300000" />
    <property name="maxWait" value="30000" />
    <property name="maxActive" value="75"/>
    <property name="maxIdle" value="7"/>        

"http--0.0.0.0-8080-741" daemon prio=10 tid=0x00007f257049c800 nid=0x2cd3 in Object.wait() [0x00007f2487ebe000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1112) - locked <0x000000055a810f00> (a org.apache.commons.pool.impl.GenericObjectPool$Latch) at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:79) at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:381) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455)