Reference: http://my.oschina.net/u/1452675/blog/203670
http://superjavason.iteye.com/blog/255423
1 /*Test Bulk Write Data*/2 LongStart =System.currenttimemillis ();3Daorecord Daorecord =NewDaorecord ();4list<t> list =NewArraylist<t>();5 for(inti = 1; I <= 1000; i++){6 for(intj = 1; J <= 1000; J + +){7T t =NewT ();8 T.seti (i);9 T.SETJ (j);Ten List.add (t); One } A } - Daorecord.insertbatch (list); -SYSTEM.OUT.PRINTLN ("Time Consuming:" + (System.currenttimemillis ()-start) + "MS");
1 //Batch Write Data test2 Public voidInsertbatch (list<t>list) {3String sql = "INSERT into T (go,back) VALUES (?,?)";4DBHelper DBH =Newdbhelper (SQL);5Connection conn =dbh.returnconn ();6 Try {7Conn.setautocommit (false); //Note this sentence must be false, for the reasons see the first reference 8PreparedStatement PS =conn.preparestatement (SQL);9 for(inti = 0; I < list.size (); i++){TenPs.setint (1, List.get (i). Geti ()); OnePs.setint (2, List.get (i). GETJ ()); A Ps.addbatch (); - if(i% 10000 = = 0){ - Ps.executebatch (); the conn.commit (); - } - } - Ps.executebatch (); + conn.commit (); - conn.close (); +}Catch(SQLException e) { A //TODO Auto-generated catch block at e.printstacktrace (); - } -}
Data sheet:
Experimental results:
"Practice" JDBC BULK INSERT Data