I have a java program that reads thousands of rows of data from a text file into a database. It uses statement batching to insert a couple thousand rows at a time.
If rows any rows fail to update, I continue attempting the rest until the end of the list. After, I go back and check which rows failed, then print the info from those rows to a log file to check later.
I'm wondering if there's a way to skip printing the failed row if it failed because of a duplicate entry. I'm fine with duplicates failing, but if the insert failed for some other reason I need the row to be output to my log file.
The way I currently do this is:
int[] updateCounts;
try {
// Do my batch updates by iterating through a vector of data
} catch (BatchUpdateException buE) {
updateCounts = buE.getUpdateCounts();
}
for (int c = 0; c < updateCounts.length; ++c) {
if (updateCounts[c] == Statement.EXECUTE_FAILED) {
// Print data from the original data vector at index c
}
}
Instead of printing every row where updateCounts is EXECUTE_FAILED, I only want to print the ones that AREN'T because of a unique key.
Between Google, StackOverflow, and the documentation for BatchUpdateException, I'm guessing there's no way to do this. But it'd be nice if there is and I just couldn't find it.