gpt4 book ai didi

java - Oracle JDBC 自动提交

转载 作者:行者123 更新时间:2023-11-29 07:59:23 25 4
gpt4 key购买 nike

假设我的代码大致类似于以下内容:(使用 oracle 10G jdbc)。在这种特定情况下会提交事务吗?

    public void someMethod(){
try {
OracleConnection connection = getConnectionFromPool();
connection.setAutoCommit(false);

// Do some transaction here - complete transaction, no errors occurred

...

//Throw my own exception here
throw new Exception("Custom Exception");


} catch (Exception e}
{
...
}
finally {
connection.setAutoCommit(true);
}
}

最佳答案

According to the 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.

但是:如果你依赖这个,就意味着你依赖驱动程序来满足这个要求——这是我不会做的事情(我永远不会依赖隐含的东西)

如果您想确保您的事务已提交,请调用 commit()

关于java - Oracle JDBC 自动提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15427222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com