oracle - Oracle JDBC - Effect of commit() rollback() close() AutoCommit() on connection - Pending Underlying transactions
问题描述
Dao Snippet
Connection connection = null;
try{
connection.setAutoCommit(false);
connection = session.getConnection(); // session here is HttpSession
Prepared Statement ...
executeUpdate(); // Step 1
insert(); // Step 2
executeUpdate(); Step 3
connection.commit();
}catch(SQLException e){
connection.rollback();
}finally{
connection.setAutoCommit(true);
}
After finishing above step, User clicks on logout
try {
// Rollback all pending transactions
connection = session.getConnection(); // session here is HttpSession
connection.rollback();
} catch (Exception e) {
logger.error(e);
} finally {
try {
connection.close();
} catch (SQLException e) {
logger.error(e);
}
}
I am using Java JDBC with Oracle.
Question
Will Step 1/2/3 execute sequentially at database level, let's say Step 1 takes 2 minutes, Step 2 takes 1 minute and Step 3 just few seconds.
Let's say above Dao method completes and underlying db is still executing updates and immediately user clicks on logout and logout code gets called which try to rollback() any pending transaction and close the DB Connection also.
Will it wait to complete the underlying transaction's or will rollback.
Will close() have any effect on uncommitted transactions
- Is it really required to set AutoCommit(true) in finally, i see locks in my database tables unless i call this statement. Ideally commit() or rollback() should make the DB back to its original state.
解决方案
推荐阅读
- visual-studio-code - VSCode pipenv 已激活问题
- asp.net-mvc - C# MVC - RazorEngine 电子邮件模板创建带有 URL 链接的按钮
- api - 将用户语音文本发送到 Alexa 技能 API 端点
- ember.js - 页面加载前的 ember js 错误
- azure - 根据电子邮件域自动将 Azure AD 中的帐户类型从来宾更改为成员
- blockchain - 如何在超级账本锯齿中查询特定资源的交易
- java - 列出 NullPointerException 休眠
- php - WordPress 移动检测/引导网格
- php - 自定义帖子类型存档页面/模板
- spring-boot - Spring Boot Camel JPA 没有本地事务加入