executeQuery() throws "Statement has been closed"

From: Hannes Erven <hannes(at)erven(dot)at>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: executeQuery() throws "Statement has been closed"
Date: 2014-07-31 08:56:09
Message-ID: 53DA04A9.2030101@erven.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi everyone,

sometimes my application (jdbc-1101, hibernate, desktop application)
reports the following "Statement has been closed" error:

Caused by: org.postgresql.util.PSQLException: Die Anweisung wurde
geschlossen.
at
org.postgresql.jdbc2.AbstractJdbc2Statement.checkClosed(AbstractJdbc2Statement.java:2631)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.getMaxRows(AbstractJdbc2Statement.java:659)
at
org.postgresql.jdbc4.Jdbc4Statement.createResultSet(Jdbc4Statement.java:34)
at
org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler.handleResultRows(AbstractJdbc2Statement.java:219)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1839)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
... 19 more

When looking at the code of getMaxRows()
(https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/jdbc2/AbstractJdbc2Statement.java
line 665):

public int getMaxRows() throws SQLException
{
checkClosed();
return maxrows;
}

... I'm wondering why there is even checkClosed() called before
returning the value of a field?
Could that check be safely removed?

It may be the case that there are concurrent calls from multiple threads
to the same Connection object, but shouldn't that be thread-safe?

(Un)fortunately the exception is logged very seldomly, so there has not
yet a pattern emerged when they happen.

Thanks for your comments,
best regards

-hannes

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2014-07-31 13:57:02 Re: executeQuery() throws "Statement has been closed"
Previous Message Dennis Gesker 2014-07-30 21:15:10 Re: XA transaction -- Linux v Windows