From what I have picked up, when a Statement is closed it is supposed to first close any ResultSets it has created. Similarly, when a Connection is closed, it is supposed to first close any Statements it has created. So -- as long as these "shoulds" hold -- you should be able to get by with closing only the connection.

But the class which you are using to implement one of these interfaces (Connection or Statement) comes, if I am not mistaken, in the specific JDBC driver which you have gotten for your database. It probably does not come from Sun. You may not have a reliable guarantee that the "shoulds" have been done. I have seen stories of memory leaks, of cases where "should" close has not happened, and something broke.

Rich Hammer

Tony Spencer wrote:
Is it necessary to close a ResultSet and PreparedStatement at the end of
some JDBC code before closing the Connection or are they closed
automatically by closing the database connection?


For example is this ok?

Connection conn = DbPool.getConnection();
ResultSet rs = null;
PreparedStatement = null;
.
.
.
conn.close();


Or should I do this?

Connection conn = DbPool.getConnection();
ResultSet rs = null;
PreparedStatement = null;
.
.
.
rs.close();
stmnt.close();
conn.close();


_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to