时间:2021-07-01 10:21:17 帮助过:21人阅读
package cn.itcast.bath;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.junit.Test;
import cn.itcast.jdbc.JDBCUtils;
public class Bath {
@Testpublic void demo1(){ Connection conn=null; PreparedStatement stat=null; long start = System.currentTimeMillis(); try { conn=JDBCUtils.getConnection(); String sql ="insert into person values(?,?,?)"; stat=conn.prepareStatement(sql); for (int i = 1; i <=50000; i++) { stat.setInt(1, i); stat.setString(2, "name"+i); stat.setString(3, "email"+i); stat.addBatch(); if(i%1000==0) { stat.executeBatch(); stat.clearBatch(); } } } catch (Exception e) { e.printStackTrace(); }finally{ long end = System.currentTimeMillis(); System.out.println("执行时间:"+(end-start)); JDBCUtils.release(stat, conn); }}
}