One, what is transaction transaction is used to guarantee the consistency of data, it consists of a set of related DML statements, the group of DML (data manipulation language, additions and deletions, no query) statement either all succeeded, or all failed. such as: online transfer is typical to use transactions to handle, to ensure the consistency of data. Ii. transactions and locks when performing transactional operations (DML statements), Oracle locks on the table being manipulated, preventing other users from modifying the structure of the table. Commit a transaction when executed with a COMMIT statement, the transaction can be committed. When a commit statement is executed, the transaction is confirmed to be changed and the transaction is ended. Delete the savepoint, release the lock, and when the commit statement is used to end the transaction, other sessions will be able to view the new data after the transaction has changed. The save point is for rollback. There is no limit to the number of save points. Rolling back a transaction savepoint (SavePoint) is a point in a transaction. Used to cancel a partial transaction, and when the transaction is ended, all the savepoint-defined save points are automatically deleted. When rollback is executed, the specified savepoint can be rolled back to the specified point. V. Several important operations of the transaction 1. Set save point SavePoint A2. Cancels the partial transaction rollback to A3. Cancel all transactions rollback NOTE: This ROLLBACK transaction must be used before commit, if the transaction is committed, So no matter how many save points you've just made, it's useless. If you do not perform a commit manually, but exit, it is automatically committed. Vi. How to use transactions in Java programs Package Com.etc.test;import Java.sql.connection;import Java.sql.drivermanager;import Java.sql.sqlexception;import Java.sql.statement;public class OracleDemo1 {public static void main (string[] args) { Connection Conn =null;try {class.forname ("oracle.jdbc.driver.OracleDriver");//1. Load driver//2. Get Connection conn = Drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:orcl", "Scott", "ORCL"); Conn.setautocommit (false); Statement sm = conn.createstatement (); Sm.Executeupdate ("Update emp set sal=sal-100 where ename= ' SCOTT '"); Sm.executeupdate ("Update emp set sal=sal+100 where ename = ' KING '); Close the Open resource Sm.close (); Conn.close ();} catch (Exception e) {//If an exception occurs, roll back the try {conn.rollback ();} catch (SQLException E1) {e1.printstacktrace ();} E.printstacktrace ();}}} Read-only transaction read-only transactions are operations that allow only queries to be performed, and do not allow transactions that perform any other DML operations, and use read-only transactions to ensure that users can only get data at a point in time.
oracle--Things---