How to properly clean up JDBC resources in Java?

后端 未结 9 1941
说谎
说谎 2020-12-16 03:17

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
{
          


        
9条回答
  •  离开以前
    2020-12-16 03:46

    ResultSet rs = //initialize here
    try {
      // do stuff here
    } finally {
      try { rs.close(); }
      catch(SQLException ignored) {}
    }
    

提交回复
热议问题