Jim Robinson wrote:
Hi, in most examples of using JDBC connections a
pattern like the following pattern is used to clean up
resources

finally
{
  if(resultSet != null) resultSet.close();
  if(statement != null) statement.close();
  if(connection != null) connection.close();
}

Shouldn't closing the connection also close the
statement and result set, making the first 2 lines
redundant?  What is the proper pattern?

Wouldn't it be better to use..

finally {
    try {
        if (statement != null) statement.close();
    } catch (Exception e) {}
    try {
        if (connection != null) connection.close();
    } catch (Exception e) {}
}

Docs say that ResultSet is closed when Statement is closed so I don't see any need to close ResultSet. But Statement is automatically closed only in garbage collection.. And of course if you create several statements during method call you can close them right after you have used them, but still nice to close in finally block if there is exception.
 

--
    jK.MkIII _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to