From: | Guillaume Rousse <Guillaume(dot)Rousse(at)univ-reunion(dot)fr> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | where to close statement ? |
Date: | 2000-04-18 12:24:47 |
Message-ID: | 00041816334200.05125@agathe |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
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 Runion
Sleep doesn't exists. Just lack of cafeine.
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Mount | 2000-04-18 13:15:17 | RE: where to close statement ? |
Previous Message | Thomas Good | 2000-04-18 11:42:25 | Re: Connecting website with SQL-database..... |