Java快速向数据库中插入大量数据 比如10万条以上
时间:2017-01-08 22:59:18
收藏:0
阅读:1957
1 String sql = "insert into table *****"; 2 //必须要有这句,要不然效果不明显 3 con.setAutoCommit(false); 4 ps = con.prepareStatement(sql); 5 for(int i=1; i<102030; i++){ 6 ps.addBatch(); 7 // 1w条记录插入一次 8 if (i % 10000 == 0){ 9 ps.executeBatch(); 10 con.commit(); 11 } 12 } 13 // 最后插入不足1w条的数据 14 ps.executeBatch(); 15 con.commit();
原文:http://www.cnblogs.com/wangguoning/p/6262943.html
评论(0)