1. 开启JDBC
rewriteBatchedStatements=true
2. 准备数据
PreparedStatement preparedStatement = connection.prepareStatement(InsertSql);
3. 插入数据并添加到批次
preparedStatement.setObject(columnIndex, resultSet.getObject(columnIndex));
preparedStatement.addBatch();
4. 批量提交并清空批次
if (resultSet.getRow() % 500 == 0) {
log.info("当前行数:" + resultSet.getRow());
preparedStatement.executeBatch();
preparedStatement.clearBatch();
}
if (resultSet.isLast()) {
log.info("最后一行:" + resultSet.getRow());
preparedStatement.executeBatch();
preparedStatement.clearBatch();
}
标签:jdbc,批量,resultSet,getRow,插入,preparedStatement
From: https://www.cnblogs.com/chenzechao/p/17832296.html