1 Phoenix的批量insert官網代碼,最佳實踐
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的在循環外圍最后提交,所以保證了,所有數據最終都是會被提交.