InsertDemo.java
import java.sql.*;
classInsertDemo
{
public static void main(String args[])throws Exception
{
Connection conn = null;
Statement stmt = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "scott", "tiger");
conn.setAutoCommit(false);
stmt = conn.createStatement( );
stmt.executeUpdate("insert into Student values (101, 'Surendra', 'MCA')");
stmt.executeUpdate("insert into Student values (102, 'Pravin', 'MCA')");
stmt.executeUpdate("insert into Student values(105, 'Vinod', 'BE')");
conn.commit();
}
catch(SQLException e)
{
Conn.rollback();
}
finally
{
try
{
if(conn != null)
{
conn.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
try
{
if(stmt != null)
{
stmt.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}