Re: When to close a Statement

From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Carlos Correia <carlos(at)m16e(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: When to close a Statement
Date: 2006-02-15 14:21:05
Message-ID: Pine.LNX.4.44.0602151615310.23408-100000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

O Carlos Correia έγραψε στις Feb 15, 2006 :

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> 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();

>
> Thanks,
>
> Carlos
> - --
> MEMΓ“RIA PERSISTENTE, Lda.
> Tel.: 219 291 591 - GSM: 967 511 762
> e-mail: geral(at)m16e(dot)com - URL: http://www.m16e.com
> AIM: m16e - ICQ: 257488263 - Jabber: m16e(at)amessage(dot)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
>
> iD8DBQFD8yaU90uzwjA1SJURAsyhAJ9twvK/oeZXrq/SEyoR9TaGr3ZNdQCgwaBC
> H3eHaRZdHmZ3FuIhs/xgDIs=
> =UI89
> -----END PGP SIGNATURE-----
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

--
-Achilleus

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Fabrice.Sznajderman 2006-02-15 14:36:10 In or Exists?
Previous Message Carlos Correia 2006-02-15 13:41:12 Re: When to close a Statement