1 /**2 * BULK Insert3 */4 @Test5 Public voidTestinsert () {6Connection conn=NULL;7Statement st=NULL;8PreparedStatement pst=NULL;9 Try {Tenconn=dbutils.getconn (); OneConn.setautocommit (false);//things can't be submitted automatically Ast=conn.createstatement (); - LongStart =System.currenttimemillis (); -String sql= "INSERT into STU1 values (?,?)"; thepst=conn.preparestatement (SQL); - intCount=0; - for(inti=1;i<=10008;i++){ -Pst.setint (1, i); +Pst.setstring (2, "Tmo" +i); - Pst.addbatch (); +count++; A if(count==2000){ at Pst.executebatch (); - Pst.clearbatch (); -Count=0; - } - } -Pst.executebatch ();//increase in the last less than 2000 in Pst.clearbatch (); -Conn.commit ();//Commit a transaction toSystem.out.println (System.currenttimemillis ()-start); +}Catch(SQLException e) { - //TODO auto-generated Catch block the e.printstacktrace (); * } $ finally{Panax NotoginsengDbutils.closeall (NULL, ST, conn); - } the}
JDBC BULK Insert operation (Addbatch)