From 39aa18b1d099604797520a089b51aef42eca3dfc Mon Sep 17 00:00:00 2001 From: "Baterdene.Z" Date: Tue, 18 Mar 2025 10:07:05 +0800 Subject: [PATCH] Update BufferedRecords.java --- .../connect/jdbc/sink/BufferedRecords.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/confluent/connect/jdbc/sink/BufferedRecords.java b/src/main/java/io/confluent/connect/jdbc/sink/BufferedRecords.java index e51d4a1f83..498a2a0499 100644 --- a/src/main/java/io/confluent/connect/jdbc/sink/BufferedRecords.java +++ b/src/main/java/io/confluent/connect/jdbc/sink/BufferedRecords.java @@ -195,15 +195,30 @@ public List flush() throws SQLException { } private void executeUpdates() throws SQLException { - int[] batchStatus = updatePreparedStatement.executeBatch(); - for (int updateCount : batchStatus) { - if (updateCount == Statement.EXECUTE_FAILED) { - throw new BatchUpdateException( - "Execution failed for part of the batch update", batchStatus); + try { + updatePreparedStatement.executeBatch(); + } catch (BatchUpdateException bue) { + SQLException nextException = bue.getNextException(); + boolean hasNonDuplicateErrors = false; + + while (nextException != null) { + if (nextException.getErrorCode() == 1 || nextException.getMessage().contains("ORA-00001")) { + log.warn("Skipping duplicate record due to ORA-00001: {}", nextException.getMessage()); + } else { + hasNonDuplicateErrors = true; + log.error("SQL Error during batch update: {}", nextException.getMessage(), nextException); + } + nextException = nextException.getNextException(); + } + + // Only throw the original exception if it contains non-duplicate errors + if (hasNonDuplicateErrors) { + throw bue; + } } - } } + private void executeDeletes() throws SQLException { if (nonNull(deletePreparedStatement)) { int[] batchStatus = deletePreparedStatement.executeBatch();