jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes Batch Update Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Batch Update Exception" Watch "Batch Update Exception" New topic

Batch Update Exception

Allen Thomas

Joined: Jul 02, 2002
Posts: 29
I am using batch updating (i.e. stmt.addBatch(sqlString), executeBatch(), etc.)
my code is:
int id = 0;
String sqlStr = "";
//createNewStatement is a customize method for creating a new statement.
Statement insertStmt = db.createNewStatement();
id = idVector.firstElement();
sqlStr = "INSERT INTO ids VALUES ('" + id + "')";

My question is: if somehow the id had a problem when it is executing the batch, how could I output the id that had the problem and continue on processing the others after it? Is there someway in retreiving the error from the executeBatch? I have tried putting it in a try-catch block, it doesn't work. I tried this:
//execute batch
}catch(BatchUpdateException b){
System.err.println("SQLException: " + b.getMessage());
System.err.println("SQLState: " + b.getSQLState());
System.err.println("Message: " + b.getMessage());
and all it does is give me a "General Error" message.
Any help would be greatly appreciated. Thank you.
It just
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Although every driver handles this differently, when I was using the Oracle thin drivers it was an all or nothing deal. If there was one exceptioin in the thousands of batched updates, then all would fail and you could not find out at which statement it failed. Don't know about the other drivers, but I assume they are similar.
I agree. Here's the link: http://aspose.com/file-tools
subject: Batch Update Exception
It's not a secret anymore!