X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 63E559DCB79 for ; Mon, 6 Feb 2006 23:06:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19561-09 for ; Mon, 6 Feb 2006 23:06:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sapo.pt (relay3.ptmail.sapo.pt [212.55.154.23]) by postgresql.org (Postfix) with SMTP id 590589DCAB0 for ; Mon, 6 Feb 2006 23:06:12 -0400 (AST) Received: (qmail 27034 invoked by uid 0); 7 Feb 2006 03:06:13 -0000 Received: from unknown (HELO sapo.pt) (10.134.35.155) by relay3 with SMTP; 7 Feb 2006 03:06:13 -0000 Received: (qmail 28335 invoked from network); 7 Feb 2006 03:06:12 -0000 X-AntiVirus: PTMail-AV 0.3.87.1 X-Virus-Status: Clean (0.05499 seconds) Received: from unknown (HELO [10.0.0.6]) (op217537@[85.241.129.42]) (envelope-sender ) by mta5 (qmail-ldap-1.03) with SMTP for ; 7 Feb 2006 03:06:12 -0000 Subject: Re: Statement has been closed (only in Windows) From: pedro farinha To: Carlos Correia Cc: "jdbc.postgres" In-Reply-To: <43E64FD8.9030704@m16e.com> References: <43E64FD8.9030704@m16e.com> Content-Type: multipart/alternative; boundary="=-dVBabjrWJohF3z7fs262" Organization: Wide World Systems Portugal Message-Id: <1139281571.2693.66.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 07 Feb 2006 03:06:12 +0000 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.946 required=5 tests=[HTML_10_20=0.945, HTML_MESSAGE=0.001] X-Spam-Score: 0.946 X-Spam-Level: X-Archive-Number: 200602/42 X-Sequence-Number: 14639 --=-dVBabjrWJohF3z7fs262 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Carlos, if you're problem is solved what is the question? if you worry about creating a lot of statements, don't. But make sure you close them after use. Also the resultSet if any. Not a big brain on this end, but why would you want to keep the statement open? P. On Sun, 2006-02-05 at 19:19, Carlos Correia wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > While testing a Java app (that's been working for years with PostgreSQL > + Linux) in a Windows box I get this error when inserting a record > whithin a transaction: > > org.postgresql.util.PSQLException: This statement has been closed. > ~ at > org.postgresql.jdbc2.AbstractJdbc2Statement.checkClosed(AbstractJdbc2Statement.java:2390) > ~ at > org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:329) > ~ at > org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:278) > > What I was doing was to keep a single connection since the beginning > until the end of the session. > > public class DbConnection > { > ~ Statement statement = null; > > ~ public Statement getStatement() throws SQLException > ~ { > ~ if( statement == null ) > ~ statement = con.createStatement(); > ~ return statement; > ~ } > } > > As there was only one connection established with the database (fat > client), this seemed OK. > > As the driver, when I ran the same app in Windos, was complaining that > the connection had been closed, I commented out the 'if' line above... > et voilá, problem solved. > > New method: > > ~ public Statement getStatement() throws SQLException > ~ { > statement = con.createStatement(); > ~ return statement; > ~ } > > As I don't like this solution (either trusting the garbage collector to > do his job or closing every statement after have been used), what I ask > is: what is the proper way of handling this kind of problem? > > Testing conditions: > > Linux: > - - Debian, Ubuntu, Gentoo, Fedora, etc. > - - PostgreSQL 7.4.x > - - pg74.216.jdbc3.jar > > Windows: > - - Windows 2000, XP > - - PostgreSQL 8.1 > - - postgresql-8.0-314.jdbc3.jar > > Thanks, > > Carlos > - -- > MEMÓRIA PERSISTENTE, Lda. > Tel.: 219 291 591 - GSM: 967 511 762 > e-mail: geral@m16e.com - URL: http://www.m16e.com > AIM: m16e - ICQ: 257488263 - Jabber: m16e@amessage.de > Skype.com username (VoIP): m16e.com > GnuPG: wwwkeys.eu.pgp.net > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFD5k/X90uzwjA1SJURAsG+AJ0RYQalem4sTxzyQd8Z/ucKsP4YLACdGyU9 > LPA+ToH9kBrgxM3kE2V1Zxg= > =v2Qt > -----END PGP SIGNATURE----- > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org --=-dVBabjrWJohF3z7fs262 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Hi Carlos, if you're problem is solved what is the question?
if you worry about creating a lot of statements, don't. But make sure you close them after use. Also the resultSet if any. Not a big brain on this end, but why would you want to keep the statement open?

P.



On Sun, 2006-02-05 at 19:19, Carlos Correia wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

While testing a Java app (that's been working for years with PostgreSQL
+ Linux) in a Windows box I get this error when inserting a record
whithin a transaction:

org.postgresql.util.PSQLException: This statement has been closed.
~        at
org.postgresql.jdbc2.AbstractJdbc2Statement.checkClosed(AbstractJdbc2Statement.java:2390)
~        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:329)
~        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:278)

What I was doing was to keep a single connection since the beginning
until the end of the session.

public class DbConnection
{
~  Statement statement = null;

~  public Statement getStatement() throws SQLException
~  {
~  	if( statement == null )
~  		statement = con.createStatement();
~  	return statement;
~  }
}

As there was only one connection established with the database (fat
client), this seemed OK.

As the driver, when I ran the same app in Windos, was complaining that
the connection had been closed, I commented out the 'if' line above...
et voilá, problem solved.

New method:

~  public Statement getStatement() throws SQLException
~  {
	statement = con.createStatement();
~  	return statement;
~  }

As I don't like this solution (either trusting the garbage collector to
do his job or closing every statement after have been used), what I ask
is: what is the proper way of handling this kind of problem?

Testing conditions:

Linux:
- - Debian, Ubuntu, Gentoo, Fedora, etc.
- - PostgreSQL 7.4.x
- - pg74.216.jdbc3.jar

Windows:
- - Windows 2000, XP
- - PostgreSQL 8.1
- - postgresql-8.0-314.jdbc3.jar

Thanks,

Carlos
- --
MEMÓRIA PERSISTENTE, Lda.
Tel.: 219 291 591 - GSM:  967 511 762
e-mail: geral@m16e.com - URL: http://www.m16e.com
AIM: m16e - ICQ: 257488263 - Jabber: m16e@amessage.de
Skype.com username (VoIP): m16e.com
GnuPG: wwwkeys.eu.pgp.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD5k/X90uzwjA1SJURAsG+AJ0RYQalem4sTxzyQd8Z/ucKsP4YLACdGyU9
LPA+ToH9kBrgxM3kE2V1Zxg=
=v2Qt
-----END PGP SIGNATURE-----

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org
--=-dVBabjrWJohF3z7fs262--