1 贴一下官方的代码
https://phoenix.apache.org/tuning_guide.html
try (Connection conn = DriverManager.getConnection(url)) {
conn.setAutoCommit(false);
int batchSize = 0;
int commitSize = 1000; // number of rows you want to commit per batch.
try (Statement stmt = conn.prepareStatement(upsert)) {
stmt.set ... while (there are records to upsert) {
stmt.executeUpdate();
batchSize++;
if (batchSize % commitSize == 0) {
conn.commit();
}
}
conn.commit(); // commit the last batch of records
}
2 解读代码
之前是没1000条,提交一次,但是不足1000的,会在循环结束后的代码的最后一次commit()中被提交,所以也不会丢失提交代码。