...
Code Block | ||
---|---|---|
| ||
Statement stmt = null; ResultSet rs = null; Connection conn = getConnection(); try { stmt = conn.createStatement(); rs = stmt.executeQuery(sqlQuery); processResults(rs); } catch(SQLException e) { // forward to handler } finally { if(rs != null) { rs.close(); } if(stmt != null) { stmt.close(); } } |
...
This compliant solution ensures that resources have been are released as required.
Code Block | ||
---|---|---|
| ||
Statement stmt = null; ResultSet rs = null; Connection conn = getConnection(); try { stmt = conn.createStatement(); rs = stmt.executeQuery(sqlQuery); processResults(rs); } catch(SQLException e) { // forward to handler } finally { try { if(rs != null) { rs.close(); } } finally { try { if(stmt != null) { stmt.close(); } } finally { conn.close(); } } } |
...