• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQLException Due to Deadlock

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use JDBC against oracle with con.setAutoCommit(false).

My transaction perform several updates so concurrent execution of my transaction may cause java.sql.SQLException: ORA-00060: deadlock detected while waiting for resource.

Normally, I think I should do a rollback and retry the transaction that failed due to deadlock. My question is how my java code identify the SQLException is caused by deadlock? Is it by parsing the String returned from exception.getMessage() to see if it contains ORA-00060? Would there be a better approach?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alec,
Unfortunately that's pretty much the only way to check - no better ways.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could take a look at SQLException's getErrorCode() method since it returns an int, from SQLException API:
getErrorCode
public int getErrorCode()
Retrieves the vendor-specific exception code for this SQLException object.

Returns:
the vendor's error code


From Oracle's Processing SQL Exceptions:


getErrorCode()

For errors originating in either the JDBC driver or the RDBMS, this method returns the five-digit ORA number.


[ April 04, 2005: Message edited by: Carol Enderlin ]
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic