I fixed some bug associated with the way you were using BasicDataSource despite the fact that I realize some of it I have some questions un-answered :)

Problem: The applying was unable to auto-connect with the database following a db failure.

Application is applying org.apache.commons.dbcp.BasicDataSource class like a TCP-connection pool for any JDBC link with Oracle db.

Fix: After a little research I came across that in BasicDataSource testOnBorrow and testOnreturn weren't set. I provided the validation query to check connections. This fixed the issue

Max no of connections in pool was set to at least one

My Understanding: The bond pool would give an association towards the application. Things I think was happening was the applying Like magic came back unhealthy collection towards the pool if this db crashed . Now because the Pool doesn't know if it's a poor connection it might give exactly the same link with the applying the next time it requires it leading to the applying not to auto-reunite to db.

Now, following the fix.. each time a bad connection is came back towards the connection pool it might be thrown away and will not be remade due to the fix I made above.

Now we all know that BasicDataSource systems the bond before giving towards the application, so that whenever application states disadvantage.close ..BasicDataSource knows the connection sits dormant anymore.. it will require proper care of either coming back the bond towards the pool or discardigg etc.

Un-answered Question: However what I don't understand is the reason why the applying Like magic return the bond towards the connection pool when its damaged[Observe that disadvantage.close technique is not known as once the connection exits not-beautifully]. There's not a way of BasicDataSource to understand the connection closed or there's ?. Can someone point me to code for your ?

I my overall understanding connect of why the fix labored ??

Searching in the test for abandoned connections, it seems that after all connections within the pool are "being used" whenever a new connection is asked for, the "in-use" connections are examined for abandonment (they conserve a timestamp of last used time).

See BasicDataSource#setRemoveAbandoned(boolean) and BasicDataSource#setRemoveAbandonedTimeout(int)

No matter how clever or otherwise your connection pool is within closing abandoned connections, it is best to ensure each connection is closed inside a finally block, e.g.:

Connection conn = getConnection();
try {
    ... // perform work
} finally {

Or apply certain other means for example Apache DBUtils.