JDBC- Transactions

JDBC Transactions

In JDBC, Connection interface provides methods to manage transaction.

Method Description
Void setAutoCommit(boolean status) If it is true each transaction is committed bydefault.
void commit() Commits the transaction.
void rollback() Cancels the transaction.


class FetchRecords{  
public static void main(String args[])throws Exception{  
Class.forName("oracle.jdbc.driver.OracleDriver");  
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","u","p");   con.setAutoCommit(false);  
   Statement stmt=con.createStatement();  
stmt.executeUpdate("insert into user420 values(190,'abhi',40000)");  
stmt.executeUpdate("insert into user420 values(191,'umesh',50000)");    
con.commit();  
con.close();  }
}