// BatchDemo.java
import java.sql.*;
import java.io.*;
classBatchDemo
{
public static void main(String args[])
{
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.addBatch("insert into Student values (101, 'ABC', 'MCA')");
stmt.addBatch("insert into Student values (102, 'XYZ', 'MCA')");
stmt.addBatch("insert into Student values(105, 'PQR', 'BE')");
stmt.executeBatch();
conn.commit();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(conn != null)
{
conn.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
try
{
if(stmt != null)
{
stmt.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}