Where to close java PreparedStatements and ResultSets?
Consider the code: PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.createStatement(myQueryString); rs = ps.executeQuery(); // process the results... } catch (java.sql.SQLException e) { log.error("an error!", e); throw new MyAppException("I'm sorry. Your query did not work."); } finally { ps.close(); rs.close(); } The above does not compile, because both PreparedStatement.close() and ResultSet.close() throw a java.sql.SQLException . So do I add a try/catch block to the finally clause? Or move the close statements into the try clause? Or just not bother calling close? For file