1

I'm trying to iterate through a SQLException Object and to filter the Error Code for each of his index.

public static void showExceptionByErrorCodeRange(SQLException ex, int range_min, int range_max){
    String msg = new String();
    int error_code = 0;
    Iterator<Throwable> itr = ex.iterator();
    while(itr.hasNext()){
        SQLException e = (SQLException)itr.next();
        error_code = e.getErrorCode();
        if(error_code >= range_min && error_code <= range_max){
           msg += e.getMessage();
        }
    }
    showErrorMsg(msg);
}

This code compile, but it looks like the SQLException has only one index because the while(itr.hasNext()) only loop once and the e.getMessage() returns this:

ORA-20000: The vendor-specific error message i need to select by my function.\n
ORA-06512: at "any_table", line x\n #<-- default SQL error message.
ORA-06512: at line 1\n #<-- default SQL error message. 

I'm able to get the e.getErrorCode() to 20000, but when i add the e.getMessage() to my msg i get all the errors in the same string. (ORA-06512)

Is there any way to seperate the errors (ORA-20000 and ORA-06512) from the getMessage() string without using string logic?

Thank you.

LAL
  • 480
  • 5
  • 13
  • This heavily depends on the implementation of the driver from the database vendor. Looks like for this case, you won't be able to do it. – Luiggi Mendoza Jul 02 '13 at 15:51
  • you might try http://docs.oracle.com/javase/6/docs/api/java/lang/Throwable.html#getCause() on the chance that Oracle's driver chains the exceptions that way instead of the SQLException specific http://docs.oracle.com/javase/6/docs/api/java/sql/SQLException.html#setNextException(java.sql.SQLException). – Brett Okken Jul 02 '13 at 16:17
  • Possible duplicate: http://stackoverflow.com/questions/10954166/java-what-information-in-error-stack-trace-do-we-typically-not-wish-to-show-use – A Nice Guy Aug 03 '15 at 10:16
  • possible duplicate of [Java: what information in error stack trace do we typically not wish to show users?](http://stackoverflow.com/questions/10954166/java-what-information-in-error-stack-trace-do-we-typically-not-wish-to-show-use) – A Nice Guy Aug 03 '15 at 10:17

0 Answers0