如果我执行 connection.setAutoCommit(false);
会发生什么,它会在数据库端创建一个新事务吗?
最佳答案
根据documentation , connection.setAutoCommit(false)
将允许您在同一事务下分组多个后续Statement
。此事务将在 connection.commit()
被调用时提交,而不是在每次 execute()
调用单个 Statement
之后(这如果启用了自动提交,就会发生这种情况)。
通过 connection.setAutoCommit()
更改自动提交模式将隐式提交 Activity 事务并创建一个新事务。来自Javadocs :
NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is committed. If setAutoCommit is called and the auto-commit mode is not changed, the call is a no-op.
关于java - connection.setAutoCommit = false 会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32739719/