More Related Content
Similar to Batch processing Demo
Similar to Batch processing Demo (20)
More from Peeyush Ranjan (8)
Batch processing Demo
- 1. Batch processing Demo
package com.nt.batch;
importjava.sql.*;
publicclassBatchProcessingDemo{
publicstaticvoidmain(String[] args) throwsException{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","password");
//create Statementobj
Statement st=con.createStatement();
//addqueriestobatch
st.addBatch("update studentsetsname='hritik'where sno=101");
st.addBatch("insertintostudentvalues(102,'ram',90,50,40,'hyderabad')");
st.addBatch("deletefromstudentwhere sno=104");
//execute the batch
int[] result=st.executeBatch();
//processthe result
intsum=0;//concept--- local variablesmusttobe initialized..
for(inti=0;i<result.length;++i){
sum=sum+result[i];
}
System.out.println("updationoccoured");
System.out.println("thenoof effectedresultsare:"+sum);
//close jdbcobjects