what is a transaction

JDBC transaction

What is a transaction :

First , let's talk about business. I think a transaction is a set of actions that operate on a database.

Transaction is one of the core concepts in modern database theory. A set of processing steps is called a transaction if either all of them occur or none of them are executed. When all steps have been completely executed as one operation, we say the transaction is committed. Because one or more of these steps failed, and no steps were committed, the transaction must be rolled back to the original system state.

Transactions must obey the ACID principles established by ISO/IEC . ACID is short for atomicity , consistency , isolation , and durability . The atomicity of a transaction means that any failure in the execution of the transaction will invalidate any modifications made by the transaction. Consistency means that when a transaction fails, all data affected by the transaction should be restored to the state before the transaction. Isolation means that modifications to data during transaction execution are not visible to other transactions until the transaction commits. Durability means ensuring that updates of committed transactions cannot be lost in the event of a system or media failure. Durability is guaranteed through database backup and restore.

JDBC  transactions are controlled with  Connection  objects. The JDBC Connection  interface ( java.sql.Connection ) provides two transaction modes: automatic commit and manual commit. java.sql.Connection  provides the following methods for controlling transactions: 
public void setAutoCommit(boolean) 
public boolean getAutoCommit() 
public void commit() 
public void rollback() 
When using 
JDBC  transaction demarcation, you can combine multiple  SQL  statements into one in business. One disadvantage of JDBC  transactions is that the scope of the transaction is limited to one database connection. JDBC  transaction cannot span multiple databases.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326069783&siteId=291194637