pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guillaume Rousse <Guillaume.Rousse@univ-reunion.fr>
To: pgsql-interfaces@postgresql.org
Subject: where to close statement ?
Date: Tue, 18 Apr 2000 16:24:47 +0400
Message-ID: <00041816334200.05125@agathe> (raw)

Hi.
Imagine the foolowing situation: i got one connection, and i have several
preparedStatements to execute, each with different parameters. Is is good
practice to close the connection in a finally() statement. But what about
statements and resultset ? Is there an advantage to close them explicitely :
-in the finally statement, before the connection.close() (see code A) ?
-in the try statement, between each statement execution for the resultset, and
between each redefinition for each preparedStatement (see code B) ?

code A:
Connection con=null;
PreparedStatement stmt=null;
Resulset rs=null;

try {
stmt=...
stmt.set...
rs=stmt.execute();
stmt.set...
rs=stmt.execute();

stmt=...
stmt.set...
rs=stmt.execute();
stmt.set...
rs=stmt.execute();
} finally {
rs.close();
stmt.close();
con.close()
}

code B:
Connection con=null;

try {
PreparedStatement stmt=...
stmt.set...
Resulset rs=stmt.execute();
rs.close();
stmt.set...
rs=stmt.execute();
rs.close();
stmt.close();

stmt=...
stmt.set...
rs=stmt.execute();
rs.close();
stmt.set...
rs=stmt.execute();
rs.close();
stmt;close();

} finally {
con.close()
}
-- 
Guillaume Rousse
Iremia - Université de la Réunion

Sleep doesn't exists. Just lack of cafeine.



view thread (9+ messages)  latest in thread

Message-ID: <00041816334200.05125@agathe>
Permalink:  ../00041816334200.05125@agathe/
Also on:    postgresql.org/message-id/00041816334200.05125@agathe

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: Guillaume.Rousse@univ-reunion.fr
  Subject: Re: where to close statement ?
  In-Reply-To: <00041816334200.05125@agathe>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox