Java Connection.close 是否回滚? [英] Does Java Connection.close rollback?
本文介绍了Java Connection.close 是否回滚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java Connection.close 是否回滚到 finally 块中?
Does Java Connection.close rollback into a finally block?.
我知道 .Net SqlConnection.close 可以做到.
I know .Net SqlConnection.close does it.
有了这个,我可以在没有 catch 的情况下制作 try/finally 块...
With this I could make try/finally blocks without catch...
示例:
try {
conn.setAutoCommit(false);
ResultSet rs = executeQuery(conn, ...);
....
executeNonQuery(conn, ...);
....
conn.commit();
} finally {
conn.close();
}
推荐答案
根据 javadoc,您应该在调用 close 方法之前尝试提交或回滚.否则结果由实现定义.
According to the javadoc, you should try to either commit or roll back before calling the close method. The results otherwise are implementation-defined.
这篇关于Java Connection.close 是否回滚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文