java.sql.SQLException:无法在 oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:4443) 上设置自动提交的情况下提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23953534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:23:17  来源:igfitidea点击:

java.sql.SQLException: Could not commit with auto-commit set on at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:4443)

javaoraclejdbc

提问by scarework

I just upgrade to new jdbc driver from classes12.jar to ojdbc7.jar

我只是将新的 jdbc 驱动程序从 classes12.jar 升级到 ojdbc7.jar

My app threw an exception when was running with ojdbc7.jar:

我的应用程序在使用 ojdbc7.jar 运行时抛出异常:

java.sql.SQLException: Could not commit with auto-commit set on
    at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:4443)
    at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:4490)
    at oracle.jdbc.driver.T4CConnection.doSetAutoCommit(T4CConnection.java:943)
    at oracle.jdbc.driver.PhysicalConnection.setAutoCommit(PhysicalConnection.java:4

My app still run normally with classes12.jar.

我的应用程序仍然使用 classes12.jar 正常运行。

I researched on oracle:

我研究了oracle:

This exception is raised for any one of the following cases:

对于以下任何一种情况,都会引发此异常:

  • When auto-commit status is set to true and commit or rollback method is called
  • When the default status of auto-commit is not changed and commit or rollback method is called
  • When the value of the COMMIT_ON_ACCEPT_CHANGES property is true and commit or rollback method is called after calling the acceptChanges method on a rowset
  • 当自动提交状态设置为 true 并调用提交或回滚方法时
  • 当 auto-commit 的默认状态没有改变并且调用 commit 或 rollback 方法时
  • 当 COMMIT_ON_ACCEPT_CHANGES 属性的值为 true 并且在行集上调用 acceptChanges 方法后调用 commit 或 rollback 方法时

But i couldn't find mistake in my source. Please help me give more explaination about this error.

但我在我的来源中找不到错误。请帮助我提供有关此错误的更多解释。

回答by Olafur Tryggvason

The latest OJDBC drivers are more compliant then they where. You can turn off this behavior for legacy code:

最新的 OJDBC 驱动程序比它们在哪里更合规。您可以为遗留代码关闭此行为:

-Doracle.jdbc.autoCommitSpecCompliant=false

It's a JVM option.

这是一个 JVM 选项。

回答by Rushi Daxini

This kind of exceptions occur when the Oracle JDBC Driver (ojdbc6.jar) version 12 or above will be used. Version 12 and above of the driver is more strictly than earlier driver versions.

使用Oracle JDBC Driver (ojdbc6.jar) 12及以上版本时会出现此类异常。版本 12 及更高版本的驱动程序比早期的驱动程序版本更严格。

You can solve the problem, you have few options:

你可以解决这个问题,你有几个选择:

  1. Change jar file to old version.( Below 12; usually issue occurs while migrating to new server)
  2. Override behavior of new jar version(ojdbc6.jar) with setting below JVM arguments.

    -Doracle.jdbc.autoCommitSpecCompliant=false

    IBM WAS users, refer this link:

  3. Set Auto Commit off in Java/SQL:

    Java:

    conn.setAutoCommit(false);

    Oracle:

    SET AUTOCOMMIT OFF

  1. 将 jar 文件更改为旧版本。(低于 12;通常在迁移到新服务器时出现问题)
  2. 使用低于 JVM 参数的设置覆盖新 jar 版本 (ojdbc6.jar) 的行为。

    -Doracle.jdbc.autoCommitSpecCompliant=false

    IBM WAS 用户,请参阅此链接

  3. 在 Java/SQL 中关闭自动提交:

    爪哇:

    conn.setAutoCommit(false);

    甲骨文:

    设置自动提交关闭

回答by Kevin

Changing this in Hibernate properties worked for me

在 Hibernate 属性中更改此设置对我有用

hibernate.connection.release_mode=auto

hibernate.connection.release_mode=auto

回答by johnson tsang

We are IBM WAS v9 with using ojbc6.jar Above configure applied to APP Server, Node agent and DMGR, then it works.

我们是 IBM WAS v9 使用 ojbc6.jar 以上配置应用到 APP Server、Node Agent 和 DMGR,然后它就可以工作了。

-Doracle.jdbc.autoCommitSpecCompliant=false

-Doracle.jdbc.autoCommitSpecCompliant=false

Dmgr: Deployment manager > Process definition > Java Virtual Machine Modify "Generic JVM arguments"

Dmgr:部署管理器 > 流程定义 > Java 虚拟机修改“通用 JVM 参数”

NodeAgent: Node agents > nodeagent > Process definition > Java Virtual Machine

NodeAgent:节点代理 > nodeagent > 进程定义 > Java 虚拟机

WebSphere Application Server: Application servers > WebSphere_Portal > Process definition > Java Virtual Machine Modify "Generic JVM arguments"

WebSphere 应用服务器:应用服务器 > WebSphere_Portal > 流程定义 > Java 虚拟机修改“通用 JVM 参数”

回答by vinS

Root Cause -

根本原因 -

PhysicalConnector.java in ojdbc6

ojdbc6 中的 PhysicalConnector.java

public void commit(int paramInt) throws SQLException {
    disallowGlobalTxnMode(114);
    if (this.lifecycle != 1) {
        SQLException sQLException = DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 8);
        sQLException.fillInStackTrace();
        throw sQLException;
    }
    .
    .

PhysicalConnector.java in ojdbc7

ojdbc7 中的 PhysicalConnector.java

public void commit(int paramInt) throws SQLException {
    disallowGlobalTxnMode(114);
    ?if (this.autoCommitSpecCompliant && getAutoCommit()) {
        throw (SQLException)DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 273).fillInStackTrace();
    }
    if (this.lifecycle != 1) {
        SQLException sQLException = DatabaseError.createSqlException(getConnectionDuringExceptionHandling(), 8);
        sQLException.fillInStackTrace();
        throw sQLException;
    ?}
    .
    .

We can see that in ojdbc7, there is some piece of code has been introduced. If autoCommitSpecCompliantand getAutoCommit()both are true, we will be getting exception.

我们可以看到在ojdbc7中,已经引入了一段代码。如果autoCommitSpecCompliantgetAutoCommit()两者都为真,我们将得到例外。

Two Fixes Available -

两个可用的修复 -

  1. set autoCommitSpecCompliant false
    Below JVM parameter to be set
    -Doracle.jdbc.autoCommitSpecCompliant=false

  2. insert below piece of code before connection.commit()

  1. set autoCommitSpecCompliant false
    下面要设置的JVM参数
    -Doracle.jdbc.autoCommitSpecCompliant=false

  2. 在下面插入一段代码之前connection.commit()

connection.setAutoCommit(false);

connection.setAutoCommit(false);