Thursday, March 19, 2009

jdbc-AutoCommit-example



import java.sql.*;
class TransDemo
{
public static void main(String[] args)throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
System.out.println(" Connected 2 DB.....");
// By default setAutoCommit true,In this case after execute
every transaction ,automatically commit transaction.

con.setAutoCommit(false);
Statement stmt=con.createStatement();
String vsql="insert into emp2 values(123,'chandu',100)";

stmt.executeUpdate(vsql);
con.commit(); //with out commit the data won't be effected
in Database in case of setAutoCommit (false).

System.out.println("Table has been created.....");

}
}



0 comments:

Post a Comment