Originally posted by Avi Abrami:
[...] I usually do this:
close the "ResultSet" close the "Statement" close the "Connection"
In fact, the
JDBC specification stipulates that closing a Statement should close all the ResultSets associated with that Statement -- with a fully compliant driver, if you execute the Statement just once and then close it, you shouldn't have to close the ResultSet explicitly.
Don't think that Connection.close() should close all open Statements, though: if you're using a connection pool that may not happen at all.
Be pedantic about closing Statements and Connections in finally blocks! Some JDBC drivers will not forgive you for any resource leaks, e.g. the Oracle driver. Even the smallest leak will eventually kill you (you'll run out of cursors).
- Peter