这些方法只能关闭
ResultSet。您仍然必须关闭全部
Statement和
Connection实例。我建议这样做
finally。就像是,
Connection conn = null;Statement stmt = null'ResultSet rs = null;try { conn = getConnection(); stmt = conn.prepareStatement(sql); stmt.setString(1, "Hello"); rs = stmt.executeQuery(); while (rs.next()) { // ... }} catch (SQLException se) { se.printStackTrace();} finally { if (rs != null) { try { rs.close(); } catch (Exception e) { e.printStackTrace(); } } if (stmt != null) { try { stmt.close(); } catch (Exception e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (Exception e) { e.printStackTrace(); } }}如果您使用我的
Close实用程序,则finally块可能是,
} finally { Close.close(rs, stmt, conn);}


