Show SQL error message

前端 未结 1 1342
予麋鹿
予麋鹿 2021-01-15 23:06

I am using JDBC to connect to MySQL in my java project. I have implemented some check constraints in the mySQL table.

I have a form in which the user enters some val

相关标签:
1条回答
  • 2021-01-15 23:33

    You can check out this:-

    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();
                    }
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题