JDBC-transaction

xiaoxiao2021-03-06  56

The transaction is to perform some SQL statements as a whole, or all statements are complete, or a statement is not executed. When the method commit or rollback is called, the current transaction ends, and another transaction begins.

By default, the new connection will be submitted automatically, that is, after the expression is performed, the COMMIT method will be automatically called. In this case, since each statement is submitted separately, an transaction consists only by one statement. If the auto-submit mode is disabled, the transaction will wait until the CommT or Rollback method is explicitly called, so it will include all the statements that have been previously called since the last call. For the second case, all statements in the transaction will be submitted or restored as a group.

Method Commit makes any changes made by the SQL statement to the database, which will also release all locks held by the transaction, and the method Rollback will give up those changes.

Sometimes the user does not want this to take effect before another change. This can be achieved by disabling automatic submission and combining two updates in a transaction. If the two updates are successful, call the commit method, so that the two update results become permanent; if one or both updates fails, call the Rollback method to restore the value to be updated. Value.

Most JDBC drivers support transactions. In fact, it is necessary to support the transaction in accordance with the JDBC driver. DatabaseMetadata gives the information given by DBMS.

转载请注明原文地址:https://www.9cbs.com/read-114312.html

New Post(0)