How to properly clean up JDBC resources in Java?

Posted by user523086 on Stack Overflow See other posts from Stack Overflow or by user523086
Published on 2010-12-22T10:22:08Z Indexed on 2010/12/22 10:54 UTC
Read the original article Hit count: 209

Filed under:
|

What is considered best practices when cleaning up JDBC resources and why? I kept the example short, thus just the cleaning up of the ResultSet.

finally
{
  if(rs != null)
    try{ rs.close(); } catch(SQLException ignored) {}
}

versus

finally
{
  try{ rs.close(); } catch(Exception ignored) {}
}

Personally I favour the second option since it is a bit shorter. Any input on this is much appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc