public static StringBuilder getStackTraceWithState ( SQLException sqle ) { SQLException sqlX = sqle ; boolean isLinkedThrowable = false ; StringBuilder trace = new StringBuilder ( EOLN ) ; SQLException tempSqlX ; do { StringWriter s = new StringWriter ( ) ; PrintWriter p = new PrintWriter ( s ) ; sqlX . printStackTrace ( p ) ; // If it is a linked exception, append link information. if ( isLinkedThrowable ) trace . append ( "---- Begin backtrace for Nested Throwables" ) . append ( EOLN ) ; // Append SQLState, error code and stack trace. trace . append ( "SQL STATE: " + sqlX . getSQLState ( ) ) . append ( EOLN ) ; trace . append ( "ERROR CODE: " + sqlX . getErrorCode ( ) ) . append ( EOLN ) ; trace . append ( s . toString ( ) ) ; // set isLinkedThrowable to true isLinkedThrowable = true ; tempSqlX = sqlX . getNextException ( ) ; } while ( ( tempSqlX != sqlX ) && ( ( sqlX = tempSqlX ) != null ) ) ; return trace ; }
This method returns a StringBuffer which includes SQL state error code and stack trace of the passed - in SQLException and all its linked exception .