Reputation: 11
I want to read a txt file which has oracle insert statements in java program and execute as a batch, If any of the record gets failed in the batch, How do i get to know the particular insert statement only got failed.
for Ex.if i have 1000 records in file and 659 record gets failed in insertion, how can i get to know the 659 record got failed in executebatch update.Is there any other process to do this please let me know.
Upvotes: 1
Views: 2156
Reputation: 203
There are two ways to handle the above situation either you check-in Java code or write the procedure
updateResult = preparedStatement.executeBatch();
checkSuccessfulUpdates(updateResult);
public static void checkSuccessfulUpdates(int[] updateCounts) throws Exception {
for (int i :updateCounts) {
if (i == Statement.EXECUTE_FAILED) {
throw new Exception("Not all rows were updated. Rolling back entire batch ");
}
}
}
Send the entire data in custom object to procedure, load it 1 by 1 by record, handle the exception within the loop, on error load the failed record in a temporary table.
Upvotes: 4