English 中文(简体)
COMMIT OR conn.setAutoCommit (true)
原标题:COMMIT OR conn.setAutoCommit(true)

我已注意到一些方案管理员使用<代码>COMMIT 采用conn.setAutoCommit(true);以终止交易或退回,从而使用一种而不是另一种方式的好处?

主要区别在哪里?

conn.setAutoCommit(true);

页: 1

statement.executeQuery(query);
statement.commit();
最佳回答

您一般应使用<代码>Connection.commit()而不是Connection.setAutoCommit(true)进行交易,除非您希望从利用交易转向按照汽车通信模式进行交易。

尽管如此,在交易中将进行交易(如果驾驶人符合JDBC 4.1光谱第10.1节),则打上<条码>Connection.setAutoCommit(true)。 但是,如果你打算在此之后留在汽车公司,那么,由于能够/拆开连接上的汽车,其连接的间接费用可能比仅仅承诺的要高(例如,它需要在交易经理之间开关,进行更多的检查等)。

您还应使用<条码>Connection.commit(,而不使用本地的“K”条码。 https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Connection.html

<>说明: 在配置<代码>Connection时,亚洲开发银行的应用程序应当使用适当的<代码>Connection方法,例如setAutoCommitset TransactionIsolation。 申请不应直接援引KQ指挥系统,以改变现有的JDBC方法时的联系配置。

确实,诸如<代码>commit()和setAutoCommit(boolean)等指挥系统可以在背景中开展更多的工作,例如封闭式<代码>ResultSets和封闭式或重订Statements。 利用“指挥编码”<条码>COMMIT,将绕过这一条,并可能使你的驾驶员/联系成为一个不正确的国家。

问题回答

<代码>conn.setAutoCommit(>); 适用于该链接,并允许执行。 单项交易中的X询问,或每条<代码>execute

As the API describes:

 void setAutoCommit(boolean autoCommit)
                    throws SQLException

Sets this connection s auto-commit mode to the given state. If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the method commit or the method rollback. By default, new connections are in auto-commit mode

简单:

conn.setAutoCommit(false); 
statement.executeQuery(query); 
statement.commit();

将与下列各点相同:

conn.setAutoCommit(true); 
statement.executeQuery(query);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签