| Refresh | Home EGTry.com

update a batch of sql statement (insert, update and delete) in one jdbc request


package dbtest;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class BatchUpdate {

	public static void main(String[] args) throws Exception {
		
		Connection conn=DbUtil.getConnection();

		Statement st=null;
		try
		{
			System.out.println("start at: "+new java.util.Date());
			st=conn.createStatement();
			for(int i=0; i<1000; i++) {
				st.addBatch("Insert Into db1.View1 (SourceSystemId, AirlineCode, SubCd, Code1, Code2, TrackingPeriod, SomeValue) values "
					+"('ZA', 'ZA', '01', 'RV', '02', 'D', "+i+")");
			}
			st.executeBatch();
			System.out.println("end at: "+new java.util.Date());
		}
		catch (Exception e) {
			e.printStackTrace(System.out);
		}
		finally {
			if(st!=null) st.close();
		}
		System.out.println("done with Batch Insert");
	}

}