Write a java program which illustrates the concept of Batch processing?



import java.sql.*;
class BatchProConcept {
 public static void main(String[] args) throws Exception {
   Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
   System.out.println("DRIVERS LOADED...");
   Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
   System.out.println("CONNECTION ESTABLISHED...");
   con.setAutoCommit(false);
   Statement st = con.createStatement();
   st.addBatch("insert into student values (3, 'j2ee')");
   st.addBatch("delete from student where sno=1");
   st.addBatch("update student set sname='java' where sno=2");
   int res[] = st.executeBatch();
   for (int i = 0; i < res.length; i++) {
    System.out.println("NUMBER OF ROWS EFFECTED : " + res[i]);
   }
   con.commit();
   con.rollback();
   con.close();
  } // main
}   // BatchProConcept


No comments:

Post a Comment