Re: executeQuery() throws "Statement has been closed"

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Hannes Erven <hannes(at)erven(dot)at>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: executeQuery() throws "Statement has been closed"
Date: 2014-07-31 13:57:02
Message-ID: CADK3HH+9x3Ni8y=KzyUsdsLN5j3cZUcbvjMKC7mmt8o3zCTK3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Well if another thread has closed the connection which I suspect is
happening here, then the results of checkClosed is correct.

I suspect you may have a concurrency problem in your code?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 31 July 2014 04:56, Hannes Erven <hannes(at)erven(dot)at> wrote:

> 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
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Hannes Erven 2014-07-31 14:21:51 Re: executeQuery() throws "Statement has been closed"
Previous Message Hannes Erven 2014-07-31 08:56:09 executeQuery() throws "Statement has been closed"