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 B82EF9DC85C for ; Wed, 15 Feb 2006 09:41:09 -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 24102-07 for ; Wed, 15 Feb 2006 09:41:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.KPNQwest.pt (smtp2.KPNQwest.pt [193.126.4.60]) by postgresql.org (Postfix) with ESMTP id C7C5C9DC835 for ; Wed, 15 Feb 2006 09:41:06 -0400 (AST) Received: from [192.168.1.11] ([193.126.36.236]) by smtp.KPNQwest.pt (8.12.10/8.12.10) with ESMTP id k1FDf8Tm005885 for ; Wed, 15 Feb 2006 13:41:09 GMT Message-ID: <43F32F78.5050209@m16e.com> Date: Wed, 15 Feb 2006 13:41:12 +0000 From: Carlos Correia User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: pt-br, pt MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: When to close a Statement References: In-Reply-To: X-Enigmail-Version: 0.93.0.0 OpenPGP: id=30354895 Content-Type: text/plain; charset=ISO-8859-7; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.162 required=5 tests=[AWL=0.162] X-Spam-Score: 0.162 X-Spam-Level: X-Archive-Number: 200602/102 X-Sequence-Number: 14699 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Achilleus Mantzios escreveu: | O Carlos Correia έγραψε στις Feb 15, 2006 : | | | Hi, | | After having had some problems with JDBC statements, as I mentioned in a | previous post, due to different behaviours between versions 7.x and 8.x | in the way Postgres deals with statements, I would like to know what is | the proper way of dealing with this. | | I realized that the need to close the statement is implementaion | dependent, and now I'm a bit confused as I can't find anything in | Postgres docs about this issue... so the questions are: | | - must I close the statement after *every* executeXXX method call? | | - should I also close the connection as well, or may I leave it open | during the application execution? | | |> Close a statement when you dont need it any more. |> e.g. |> PreparedStatement neinsst=con.prepareStatement("insert into |> sparecasesdets(scid,no,descr,qty_obd,qty_req,drgno,partno) |> VALUES(?,?,?,?,?,?,?)"); | |> java.util.Enumeration en = request.getParameterNames(); | |> for (;en.hasMoreElements();) { | |> String str_no=(String) en.nextElement(); |> boolean isdascd = str_no.startsWith("no_dascdid"); |> ..... |> neinsst.setInt(1,Integer.parseInt(scid)); |> ..... |> int rc = neinsst.executeUpdate(); |> .... |> } |> neinsst.close(); | I haven't fully test it with PreparedStatement yet, but with normal statements -- the ones you get after calling connection's createStatement() -- after several executeXXX() calls I get an SQLException saying "the connection has been closed" (this problem only occurs with PostgreSQL v8.x in Windows -- I haven't been able to test in Linux yet -- with v. 7.x I haven't notice such problems). 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 iD8DBQFD8y9490uzwjA1SJURAvixAKCuXSPDP3FPdxV9med+wGsh70QrBQCgr9ax qDq8B8xu5D43aqFNaY1EA44= =cqL5 -----END PGP SIGNATURE-----