Phoenix连接工具类&批量提交

目录

  1. Phoenix连接工具类
  2. Phoenix批量提交

Phoenix连接工具类

Phoenix批量提交

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();
batchSize = 0;
}
}
conn.commit(); // commit the last batch of records
}
Author: Tunan
Link: http://yerias.github.io/2020/12/08/phoenix/3/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.