File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes This statement has been closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "This statement has been closed" Watch "This statement has been closed" New topic

This statement has been closed

Surender Suri
Ranch Hand

Joined: May 28, 2010
Posts: 46

I am not sure if this is the right section to ask this question. Anyway it is related partly with multi-threading.

We have a web application running on tomcat, using dbcp (1.2) for connection pooling. Our application is heavely multi-threaded and is working fine with no issues, but recently we added a new flow where we are using similar multi threading as in rest of our app and we started seeing below issue consistently.. It does not happen if the new request runs in single thread.. org.postgresql.util.PSQLException: This ResultSet is closed.
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed(
at org.postgresql.util.PSQLException: This statement has been closed.
at org.postgresql.jdbc2.AbstractJdbc2Statement.checkClosed(
at org.postgresql.jdbc2.AbstractJdbc2Statement.getMaxRows(
at org.postgresql.jdbc3.Jdbc3Statement.createResultSet(
at org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler.handleResultRows(
at org.postgresql.core.v3.QueryExecutorImpl$1.handleResultRows(
at org.postgresql.core.v3.QueryExecutorImpl.processResults(
at org.postgresql.core.v3.QueryExecutorImpl.execute(
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(
at org.apache.commons.dbcp.DelegatingStatement.executeQuery(

Below is the sample code of processQuery method.

Nothing is changed with respect to configuration ect.. the rest of the app and flows works fine. I tried with updating the dbcp jar with latest version, but no effect.

Any idea's on what might be causing the issue? is it multi-threading or connection pooling related ?


Richard Tookey

Joined: Aug 27, 2012
Posts: 1166

I don't know what is causing your problem but I don't understand why you have the code

at all since the 'finally' clause will close the statement and return the connection to the pool! Also, since both 'stmt' and 'conn' are local variables there is no need to set them to null since they will go out of scope as soon as the method exits.

I agree. Here's the link:
subject: This statement has been closed
It's not a secret anymore!