JDBC批量插入
作者:互联网
public void batchInsert() { String sql = "insert into goods(name) values(?)"; Connection conn = null; PreparedStatement ps = null; try { conn = JDBCUtils.getConnection(); conn.setAutoCommit(false); ps = conn.prepareStatement(sql); for (int i = 0; i < 10000; i++) { ps.setObject(1,"name_" + i); ps.addBatch(); if (i % 500 == 0) { ps.executeBatch(); ps.clearBatch(); } } conn.commit(); } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtils.closeResource(conn,ps); } }
标签:ps,JDBC,name,批量,插入,JDBCUtils,sql,null,conn 来源: https://www.cnblogs.com/tsai-87/p/16074787.html