我现在用这个方法关闭
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (con != null) con.close();
}
假设关闭st的时候发生了错误,那么con就关闭不了了!
关闭rs或关闭st的时候会不会出现错误呢?
如果关闭rs或关闭st的时候出现错误,那么con就关闭不了了阿
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (con != null) con.close();
}
假设关闭st的时候发生了错误,那么con就关闭不了了!
关闭rs或关闭st的时候会不会出现错误呢?
如果关闭rs或关闭st的时候出现错误,那么con就关闭不了了阿
try {
if (rs != null) rs.close();
if (st != null) st.close();
if (con != null) con.close();
}
finally {
rs= null;
st=nul;;
conn= null;
}
}
http://www.hibernate.org.cn/viewtopic.php?t=13649这里全是讨论这个问题的。。
名字是: 你擦了吗?确定擦了?真的确定擦了?
你这个方法也没有关闭阿,只是负值为null了
} finally {
try {
if (rs != null) rs.close();
if (st != null) st.close();
if (con != null) con.close();
}
finally {
con.close();
}
}
决定用以下方法,看看有没有什么弊端?} finally {
try {
try {
if (rs != null) rs.close();
} finally {
if (st != null) st.close();
}
} finally {
if (con != null) con.close();
}
}