This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

batchupdateException.getUpdateCounts() doesnot return correct result as per JDBC api  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we are using following thin driver
db.driverClassName=oracle.jdbc.driver.OracleDriver (type 4)

Now when i execute the following code,
int[] update = prepStmt.executeBatch();
and then lets say i try to insert a null in non-null column , i end up in following catch up block

catch (BatchUpdateException b) {
wfdata_dbConnection.rollback();
System.err.println("----BatchUpdateException----");
System.err.println("SQLState: " + b.getSQLState());
System.err.println("Message: " + b.getMessage());
System.err.println("Vendor: " + b.getErrorCode());
System.err.print("Update counts: ");
int[] updateCounts = b.getUpdateCounts();
for (int i = 0; i < updateCounts.length; i++) {
System.err.print(updateCounts[i] + " ");
}
}

Now JDBC api says following
If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will have an element for every command in the batch rather than only elements for the commands that executed successfully before the error. In the case where the driver continues processing commands, the array element for any command that failed is Statement.EXECUTE_FAILED.

but in my case, when i look into int[] returned by updateCounts , it consist of -3 all throughout (for as many stmts as i had batched up) regardless whether there was error at first stmt in batch or last stmt in batch .

This seems to be strange to me and really i am posting this Question here is because i find it hard that Oracle driver is not behaving as stated in api where it should either just return me an array with top n successfull stmts or return me an array with -2 and -3 for successful and failed stmts respectively

please correct me if i someone thinks that i am making some mistake.
 
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This behaviour is actually documented - scroll down to a section titled "Error Handling in the Oracle Implementation of Standard Batching" and note the last paragraph in that section.

Oracle has two batching modes - Oracle specific and JDBC compatible. The documentation states that JDBC compatible mode will not gain much performance improvement. I'd say this feature is a little bit neglected.

The Oracle specific batching (described in the documentation I've linked above) is very easy to use and brings significant performance increase, although it is limited to a single PreparedStatement at any time. See the documentation for the details.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!