<p>1,ResultSet不能被返回,因为在连接关闭以后,ResultSet中的值就失效了。在connect被关闭以后,所 有connect创建的对象都会被关闭。</p>
<p> 2,jdbc中释放资源的严谨的写法。</p>
<p><textarea cols="50" rows="15" name="code" class="java:collapse:showcolumns">public static void free(ResultSet rs, Statement st, Connection conn) {
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (st != null)
st.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}</textarea></p>
<p> 2,jdbc中释放资源的严谨的写法。</p>
<p><textarea cols="50" rows="15" name="code" class="java:collapse:showcolumns">public static void free(ResultSet rs, Statement st, Connection conn) {
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (st != null)
st.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}</textarea></p>