Java SQLException printSQLException(SQLException ex)

Here you can find the source of printSQLException(SQLException ex)

Description

print SQL Exception

License

Open Source License

Declaration

public static void printSQLException(SQLException ex) 

Method Source Code

//package com.java2s;

import java.sql.SQLException;

public class Main {
    public static void printSQLException(SQLException ex) {
        for (Throwable e : ex) {
            if (e instanceof SQLException) {
                if (ignoreSQLException(((SQLException) e).getSQLState()) == false) {
                    e.printStackTrace(System.err);
                    System.err.println("SQLState: " + ((SQLException) e).getSQLState());
                    System.err.println("Error Code: " + ((SQLException) e).getErrorCode());
                    System.err.println("Message: " + e.getMessage());
                    Throwable t = ex.getCause();
                    while (t != null) {
                        System.out.println("Cause: " + t);
                        t = t.getCause();
                    }//www.ja  v  a2  s . co m
                }
            }
        }
    }

    public static boolean ignoreSQLException(String sqlState) {
        if (sqlState == null) {
            System.out.println("The SQL state is not defined!");
            return false;
        }
        // X0Y32: Jar file already exists in schema
        if (sqlState.equalsIgnoreCase("X0Y32"))
            return true;
        // 42Y55: Table already exists in schema
        if (sqlState.equalsIgnoreCase("42Y55"))
            return true;
        return false;
    }
}

Related

  1. printExceptionAndRollback(Connection conn, Exception e)
  2. printExceptions(OutputStream os, SQLException sqlEx)
  3. printSQLException(SQLException e)
  4. printSQLException(SQLException e)
  5. printSQLException(SQLException ex)
  6. printSqlException(SQLException sqlex)
  7. printSQLExceptionToErrorLog(Log logger, String message, List sqlExceptions)
  8. printStackTrace(final Throwable exception)
  9. printStackTrace(SQLException e)