public void fun() throws SQLException{
Connection con=JdbcUtils.getConnection();
String sql="INSERT INTO user VALUES(?,?)";
PreparedStatement pps=con.prepareStatement(sql);
for(int i=1;i<1000;i++)
{
pps.setInt(1, i);
pps.setString(2, "stu"+i);
pps.addBatch();
}
pps.executeBatch();
}
注意:mysql默认关闭批处理,打开批处理的方式:在url参数后添加
?rewriteBatchedStatement=true