• Post Reply Bookmark Topic Watch Topic
  • New Topic

SQLException Due to Deadlock

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • 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?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36007
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alec,
Unfortunately that's pretty much the only way to check - no better ways.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • 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 ]
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!