aspose file tools
The moose likes JDBC and the fly likes SQLException Due to Deadlock Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "SQLException Due to Deadlock" Watch "SQLException Due to Deadlock" New topic
Author

SQLException Due to Deadlock

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 568
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 26192
    
  66

Alec,
Unfortunately that's pretty much the only way to check - no better ways.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1348
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 ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: SQLException Due to Deadlock
 
Similar Threads
Spring - Hibernate Multithreading Transaction Issue
plssssss Help me!!
Retry on getting exception
Hit ORA-00060: deadlock detected while waiting
Continuing a transaction after deadlock