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); } }