B
Blah Blah
hi there,
i'm trying to figure out when and where i have to close my
java.sql.Statement objects. i have the following code:
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
conn = ds.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery("select * from foo");
while (rset.next()) {}
rset.close();
rset = null;
/**** do i need this code?
stmt.close();
stmt=null;
stmt=conn.createStatement();
****/
rset = stmt.executeQuery("select * from bar");
rset.close();
rset = null;
} catch (SQLException sqle) {
} finally {
try {if (rset != null) rset.close();} catch (SQLException e) {}
try {if (stmt != null) stmt.close();} catch (SQLException e) {}
try {if (conn != null) conn.close();} catch (SQLException e) {}
}
the question is - do i need to close my Statement, and create a new one,
after every query? or can i just create one statement, and leave it alone
until i'm done with everything?
daniel
i'm trying to figure out when and where i have to close my
java.sql.Statement objects. i have the following code:
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
conn = ds.getConnection();
stmt = conn.createStatement();
rset = stmt.executeQuery("select * from foo");
while (rset.next()) {}
rset.close();
rset = null;
/**** do i need this code?
stmt.close();
stmt=null;
stmt=conn.createStatement();
****/
rset = stmt.executeQuery("select * from bar");
rset.close();
rset = null;
} catch (SQLException sqle) {
} finally {
try {if (rset != null) rset.close();} catch (SQLException e) {}
try {if (stmt != null) stmt.close();} catch (SQLException e) {}
try {if (conn != null) conn.close();} catch (SQLException e) {}
}
the question is - do i need to close my Statement, and create a new one,
after every query? or can i just create one statement, and leave it alone
until i'm done with everything?
daniel