写入的时候,可以将SQL 拆分,重组即可
String url = "jdbc:mysql://localhost:3306/mydatabase";
String user = "username";
String password = "password";
Connection conn = DriverManager.getConnection(url, user, password);
conn.setAutoCommit(false); // 关闭自动提交
PreparedStatement pstmt = conn.prepareStatement("delete from `db1`.`table1` where `uid` = ? and `groupby` = ?");
for (int i = 0; i < 100; i++) {
pstmt.setString(1, "value1");
pstmt.setString(2, "value2");
pstmt.addBatch(); // 将当前语句添加到批处理中
}
pstmt.executeBatch(); // 执行批处理中的所有语句
conn.commit(); // 提交事务
conn.close(); // 关闭连接
通过batch 的方式写入 tidb,这样会比较省事,性能也还不错