I guess I understood the point with the "Random Connection Closed
Exceptions" Problem.
See at the end of
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
As I understand, only the connection itself must be protected this way.
The statement and ResultSet must not. Is the following, simplified code
also correct?
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = ... get connection from connection pool ...
stmt = conn.createStatement("select ...");
rs = stmt.executeQuery();
... iterate through the result set ...
rs.close();
stmt.close();
conn.close(); // Return to connection pool
conn = null; // Make sure we don't close it twice
} catch (SQLException e) {
... deal with errors ...
} finally {
try {
rs.close();
} catch (SQLException e) {
// deal with errors
}
try {
stmt.close();
} catch (SQLException e) {
// deal with errors
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// deal with errors
}
conn = null;
}
}
Thanks.
--
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org