The following transaction has been selected as a victim of a deadlock:

public void side2() throws SQLException, InterruptedException {
    TestConnectionPool connectionPool = new TestConnectionPool();
    try(Connection connection = connectionPool.get()){
        try {
            PreparedStatement update1 = connection.prepareStatement("update t2 set j=j-1");
            PreparedStatement update2 = connection.prepareStatement("update t1 set j=j-1");
        }catch (SQLException ex){
            System.out.println("ex.getErrorCode()=" + ex.getErrorCode());
            System.out.println("ex.getSQLState()=" + ex.getSQLState());

Its output is as follows:


What should I use to determine whether the error is a deadlock: error code, SQL State, or both?

1 Answer 1


I guess the ex.getErroCode() has returned ORA-00060: deadlock detected while waiting for resource which is deadlock error. Add ORA in front of the returned error code then search online or use Oracle supplied tool oerr as demonstrated below to determine the error details.

An error code. This is an integer value identifying the error that caused the SQLException instance to be thrown. Its value and meaning are implementation-specific and might be the actual error code returned by the underlying data source. Retrieve the error by calling the method SQLException.getErrorCode.More...

[oracle@orcl trace]$ oerr ora 60

00060, 00000, "deadlock detected while waiting for resource"

Cause: Transactions deadlocked one another while waiting for resources.

Action: Look at the trace file to see the transactions and resources involved. Retry if necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.