Java SQLException parseRemoteException(Throwable t)

Here you can find the source of parseRemoteException(Throwable t)

Description

parse Remote Exception

License

Open Source License

Declaration

private static SQLException parseRemoteException(Throwable t) 

Method Source Code


//package com.java2s;

import java.sql.SQLException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern PATTERN = Pattern.compile("ERROR (\\d+) \\((\\w+)\\): (.*)");

    private static SQLException parseRemoteException(Throwable t) {
        String message = t.getLocalizedMessage();
        if (message != null) {
            // If the message matches the standard pattern, recover the SQLException and throw it.
            Matcher matcher = PATTERN.matcher(t.getLocalizedMessage());
            if (matcher.find()) {
                int errorCode = Integer.parseInt(matcher.group(1));
                String sqlState = matcher.group(2);
                return new SQLException(matcher.group(), sqlState, errorCode, t);
            }/*from  ww  w  . j  a va2  s  . c  om*/
        }
        return null;
    }
}

Related

  1. logSqlError(SQLException ex, Logger logger)
  2. mergeException(List exceptions)
  3. mergeException(List exceptions)
  4. mergeSQLExceptionMsg(final StringBuilder msgBuilder, final SQLException e, final String prefix)
  5. oracleSessionHasBeenKilled(Exception exception)
  6. printExceptionAndRollback(Connection conn, Exception e)
  7. printExceptions(OutputStream os, SQLException sqlEx)
  8. printSQLException(SQLException e)
  9. printSQLException(SQLException e)