Re: When to close a Statement - Mailing list pgsql-jdbc

From Markus Schaber
Subject Re: When to close a Statement
Date
Msg-id 43F32B48.8080104@logix-tt.com
Whole thread Raw
In response to When to close a Statement  (Carlos Correia <carlos@m16e.com>)
List pgsql-jdbc
Hi, Carlos,

Carlos Correia wrote:

> 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?

No, only close it if you don't need it any more.

But reusing a statement closes the ResultSet from the last query used
with this statement. The same is for begin/abort/commit.

> - should I also close the connection as well, or may I leave it open
> during the application execution?

Keep it open as long as possible (or use a connection pool), because
reopening a connection is slow.

HTH,
Markus
--
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org

pgsql-jdbc by date:

Previous
From: "A Redhead"
Date:
Subject: Re: Connection reauthentication in jboss datasource connection pool
Next
From: Markus Schaber
Date:
Subject: Re: In or Exists?