Tomcat DBCP: Data source is closed

After updating to the latest version of Tomcat I started getting the following error when redeploying a webapp from inside eclipse:
java.sql.SQLException: Data source is closed
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(

It seemed to be related to an updated version of DBCP that is used inside tomcat (I get Tomcat to manage my datasource). After tracing the code a bit I discovered it was because I called this, in my Filter.destroy() to do clean up:
((BasicDataSource) dataSource).close();

Older versions of Tomcat (6.0.26 and below), didn't care if you called it. When the webapp was reloaded, the datasource still worked. But as of 6.0.28, the newer version of DBCP seems to cause problems.

So if you want to clean up after the webapp, use the removeAbandoned attribute in the Tomcat Configuration on the datasource, that way DBCP just cleans up after itself.

NOTE: I'm using the tomcat-dbcp.jar from Tomcat 7 in my Tomcat 6 instance so that I'm able to use the JDBC 4 functionality. Hence the link to the new documentation, Tomcat 6 Configuration also has it though.


  1. java.sql.SQLException: Data source is closed
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(
    at org.apache.commons.dbcp.BasicDataSource.getConnection(

    I have been getting the same.. But i didn't call datasourse.close() any ware in my application. Please help me out to fix this issue

  2. I am seeing the same issue in my application.
    Did you get any solution to this issue


Post a Comment