Re: executeQuery() throws "Statement has been closed"
От | Dave Cramer |
---|---|
Тема | Re: executeQuery() throws "Statement has been closed" |
Дата | |
Msg-id | CADK3HH+9x3Ni8y=KzyUsdsLN5j3cZUcbvjMKC7mmt8o3zCTK3A@mail.gmail.com обсуждение исходный текст |
Ответ на | executeQuery() throws "Statement has been closed" (Hannes Erven <hannes@erven.at>) |
Ответы |
Re: executeQuery() throws "Statement has been closed"
|
Список | 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?
On 31 July 2014 04:56, Hannes Erven <hannes@erven.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
В списке pgsql-jdbc по дате отправления: