Skip to content

Commit 756e22f

Browse files
committed
Solves issue-2548
1 parent 3d12e6e commit 756e22f

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

examples/jdbc/src/main/java/com/clickhouse/examples/jdbc/Basic.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,20 @@ static void insertDateWithPreparedStatement(String url, Properties properties) t
5959
pstmt.setString(3, "Alice");//Set the third parameter to "Alice"
6060
pstmt.setObject(4, Collections.singletonMap("key1", "value1"));
6161
pstmt.addBatch();//Add the current parameters to the batch
62+
pstmt.executeBatch();//Execute the batch
6263

6364
pstmt.setObject(1, ZonedDateTime.now());
6465
pstmt.setInt(2, 2);//Set the second parameter to 2
6566
pstmt.setString(3, "Bob");//Set the third parameter to "Bob"
6667
pstmt.setObject(4, Collections.singletonMap("key2", "value2"));
6768
pstmt.addBatch();//Add the current parameters to the batch
6869

70+
pstmt.setObject(1, ZonedDateTime.now());
71+
pstmt.setInt(2, 2);//Set the second parameter to 2
72+
pstmt.setString(3, "Chris");//Set the third parameter to "Chris"
73+
pstmt.setObject(4, Collections.singletonMap("key3", "value3"));
74+
pstmt.addBatch();//Add the current parameters to the batch
75+
6976
pstmt.executeBatch();//Execute the batch
7077
}
7178
}

jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,23 @@ public long[] executeLargeBatch() throws SQLException {
332332
}
333333

334334
private List<Integer> executeBatchImpl() throws SQLException {
335+
List<Integer> results;
335336
if (insertStmtWithValues) {
336-
return executeInsertBatch();
337+
results = executeInsertBatch();
337338
} else {
338-
List<Integer> results = new ArrayList<>();
339+
results = new ArrayList<>();
339340
for (String sql : batch) {
340341
results.add((int) executeUpdateImpl(sql, localSettings));
341342
}
342-
return results;
343343
}
344+
clearBatch();
345+
return results;
346+
}
347+
348+
@Override
349+
public void clearBatch() throws SQLException {
350+
super.clearBatch(); /// clear super#batch
351+
batchValues.clear();
344352
}
345353

346354
private List<Integer> executeInsertBatch() throws SQLException {

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ private List<Integer> executeBatchImpl() throws SQLException {
416416
for (String sql : batch) {
417417
results.add(executeUpdate(sql));
418418
}
419+
clearBatch();
419420
return results;
420421
}
421422

0 commit comments

Comments
 (0)