package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Demo05 {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;//用Statement是因为prepareStatement需要预编译 占用一定的空间 如果数据量很大 可能会碰到磁盘空间不足,
ResultSet rs = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/jdbcTest?serverTimezone" +
"=UTC&characterEncoding=utf-8&useSSL=false","root","root");
conn.setAutoCommit(false);//想用批处理 一定要把自动提交关闭
long start = System.currentTimeMillis();
stmt = conn.createStatement();
for (int i = 0; i < 20000; i++) {
stmt.addBatch("insert into to_user (username, pwd, regTime) values('john" + i+
java jdbc 批处理batch
最新推荐文章于 2024-05-11 21:34:15 发布