Received: from iremia.univ-reunion.fr (iremia.univ-reunion.fr [194.199.73.10]) by hub.org (8.9.3/8.9.3) with ESMTP id IAA15470 for ; Tue, 18 Apr 2000 08:28:13 -0400 (EDT) (envelope-from Guillaume.Rousse@univ-reunion.fr) Received: from agathe (agathe.univ.run [10.10.2.24]) by iremia.univ-reunion.fr (8.9.1a/jtpda-5.3.1/jlo(98)) with SMTP id QAA21770 for ; Tue, 18 Apr 2000 16:27:01 +0400 (GMT+4) From: Guillaume Rousse Organization: Université de la Réunion To: pgsql-interfaces@postgresql.org Subject: where to close statement ? Date: Tue, 18 Apr 2000 16:24:47 +0400 X-Mailer: KMail [version 1.0.28] Content-Type: text/plain MIME-Version: 1.0 Message-Id: <00041816334200.05125@agathe> Content-Transfer-Encoding: 8bit X-Archive-Number: 200004/115 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.