How to commit changes
1. void commit() - Makes all changes made since the previous commit / rollback permanent add releases any database locks currently held by this connection object.
2. void close() - Releases the connection objects database and JDBC resources immediately instead of waiting for them to be automatically released.
How to undo changes
1. void rollback() - Undo all changes made in the current transaction and releases any database locks currently held by this connection object.
2. void rollback(Savepoint savepoint) - Undo all changes made after the given savepoint object was set.
PROGRAM
package Package1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Test27 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "rakesh");
con.setAutoCommit(false);
Statement st = con.createStatement();
int c;
c = st.executeUpdate("update emp set sal=sal+100 where deptno=10");
System.out.println(c);
con.rollback();
c=st.executeUpdate("delete from dept where deptno=12");
System.out.println(c);
con.commit();
c=st.executeUpdate("update emp set sal=sal+200 where deptno=20");
con.close();
}
}
No comments:
Post a Comment