Subject Connection Statement ResultSet Closing
Author heilsteffen
Hi

That is the recommended way to open/close connections, statements,
resultsets?
Currently I am doint it this way [surely with connection Pooling].


final static void loadAllUsers()
throws AdminException
{
Connection connection = null;
Statement statement = null;
ResultSet data = null;
try {
connection = Database.getConnection();
statement = connection.createStatement();
data = statement.executeQuery( USER_QUERY );
while ( data.next() )
load( data );
data.close();
Security.setUsersPreloaded( true );
} catch ( Exception e ) {
throw new AdminException( "loadAllUsers failed: " + e );
} finally {
try { data.close(); } catch ( Exception e ) { }
try { statement.close(); } catch ( Exception e ) { }
try { connection.close(); } catch ( Exception e ) { }
}
}

Actually I think this is a bit too pessimistic and maybe a little
slow using all these try-blocks.

How are you handling such things?

cu,
Steffen