1

I would like to know if there is a way to say pass autocommit = false in "info" parameter to DriverManager.getConnection(String url, Properties info) and get db connection which shall have autocommit disabled by default. I know that I can get the connection and then invoke setAutocommit to false but would like to know if this is achievable.

4

1 回答 1

1

一般来说:没有。JDBC 规范指定新创建的连接最初是autoCommit = true. 从 JDBC 4.2,第 10.1.1 节:

Connection默认设置是在创建对象时启用自动提交模式。

但是,使用默认值可能意味着允许驱动程序具有替代配置。不幸的是,JDBC 规范中的语言并不总是正式的,因此其意图可能是最初Connection 必须始终自动提交。

因此,可能有些驱动程序具有最初禁用 autoCommit 的属性,但您应该在该特定驱动程序的文档中查找。这仅适用于该特定驱动程序,而不适用于所有 JDBC 驱动程序。

于 2014-09-17T13:07:32.357 回答