核心api rewriteBatchedStatements=true,statement.addBatch();
计算时间:System.currentTimeMillis();
@Test
public void afterPiLiang() throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
//2.建立连接
Connection connection = DriverManager.getConnection("jdbc:mysql:///atguigu?rewriteBatchedStatements=true", "root", "123456");
//3.创建sql语句
String sql = "insert into t_user(account,password,nickname) values(?,?,?)";
//4.创建prepareStatement,Statement接口调用运回主键方法
PreparedStatement statement = connection.prepareStatement(sql);
long start = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
statement.setObject(1,"diingzhen"+i);
statement.setObject(2,"1234"+i);
statement.setObject(3,"理塘王"+i);
}
statement.addBatch();
long end = System.currentTimeMillis();
double time = end - start;
System.out.println(time);
statement.close();
connection.close();
}