Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XCm9t-0002IN-SZ for pgsql-jdbc@arkaria.postgresql.org; Thu, 31 Jul 2014 08:56:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XCm9t-0006E0-CR for pgsql-jdbc@arkaria.postgresql.org; Thu, 31 Jul 2014 08:56:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XCm9s-0006Dt-DQ for pgsql-jdbc@postgresql.org; Thu, 31 Jul 2014 08:56:20 +0000 Received: from chello080108195078.3.13.vie.surfer.at ([80.108.195.78] helo=margarita.erven.at) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XCm9o-0001Np-NE for pgsql-jdbc@postgresql.org; Thu, 31 Jul 2014 08:56:18 +0000 Received: from [192.168.217.21] (unknown [193.9.252.69]) by margarita.erven.at (Postfix) with ESMTPSA id E669177000E0 for ; Thu, 31 Jul 2014 10:56:11 +0200 (CEST) Message-ID: <53DA04A9.2030101@erven.at> Date: Thu, 31 Jul 2014 10:56:09 +0200 From: Hannes Erven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: executeQuery() throws "Statement has been closed" Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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