List of utility methods to do SQLException
String[] | getAllMessagesArray(Throwable t, boolean includeExceptionName) Returns all the messages for the throwable and all of its causes. ArrayList<String> list = new ArrayList<String>(); if (t != null) { String msg; String tMessage = t.getMessage(); if (includeExceptionName) { msg = t.getClass().getName() + ":" + tMessage; } else { msg = (tMessage != null) ? tMessage : t.getClass().getName(); ... |
String | getAllSqlExceptionMessages(SQLException t) Same as #getAllSqlExceptionMessages(Throwable,boolean) with the "include exception name" parameter set to true .
return getAllSqlExceptionMessages(t, true);
|
String[] | getAllSqlExceptionMessagesArray(SQLException t, boolean includeExceptionName) Returns all the messages for the SQL Exception and all of its causes. ArrayList<String> list = new ArrayList<String>(); if (t != null) { String tMessage = t.getMessage(); if (includeExceptionName) { list.add(t.getClass().getName() + ":" + tMessage); } else { list.add((tMessage != null) ? tMessage : t.getClass().getName()); while ((t.getNextException() != null) && (t != t.getNextException())) { String msg; t = t.getNextException(); tMessage = t.getMessage(); if (includeExceptionName) { msg = t.getClass().getName() + ":" + tMessage; } else { msg = (tMessage != null) ? tMessage : t.getClass().getName(); list.add(msg + "(error-code=" + t.getErrorCode() + ",sql-state=" + t.getSQLState() + ")"); return list.toArray(new String[list.size()]); |
String | getClassWhichThrowsException(SQLException e) get Class Which Throws Exception for (StackTraceElement element : e.getStackTrace()) { if (element.getClassName().contains("pfreiberg")) { String[] tokens = element.getClassName().split("\\."); return tokens[tokens.length - 1]; return ""; |
Throwable | getExceptionCause(Throwable e) Gets the cause from an exception. if (e instanceof java.sql.SQLException) { return e; } else if (e instanceof java.sql.BatchUpdateException) { return e; } else if (e.getCause() != null) { return getExceptionCause(e.getCause()); } else { return e; ... |
String | getExceptionMessage(Throwable t) Returns the cause of a trigger exception (BatchupdateException). if (t.getCause() instanceof BatchUpdateException && ((BatchUpdateException) t.getCause()).getNextException() != null) { final BatchUpdateException bue = (BatchUpdateException) t.getCause(); return bue.getNextException().getMessage(); return t.getMessage(); |
String | getFullMessage(SQLException exception) Retrieves the full message from SQLException. StringBuilder errorTrace = new StringBuilder(exception.getMessage()); SQLException next = exception; while (next != null) { errorTrace.append("; "); errorTrace.append(next.getMessage()); next = next.getNextException(); Throwable cause = exception.getCause(); ... |
SQLException | getNextExceptionFromLastCause(Exception e) get Next Exception From Last Cause Throwable lastCause = getLastCause(e); SQLException nextException = null; if (lastCause instanceof SQLException) { nextException = ((SQLException) lastCause).getNextException(); return nextException; |
StringBuffer | getSingleSQLExceptionCause(SQLException e) get Single SQL Exception Cause StringBuffer message = new StringBuffer(); message.append("SQL State:").append(e.getSQLState()).append("\n"); message.append("Error Code:").append(e.getErrorCode()).append("\n"); StringWriter string_writer = new StringWriter(); PrintWriter writer = new PrintWriter(string_writer); e.printStackTrace(writer); message.append(string_writer.getBuffer()); return message; ... |
int | getSQLErrorCode(SQLException ex_) Sometimes the SQL error code isn't set and we have to pull it from the message. int error = ex_.getErrorCode(); if (error != 0) return error; String msg = ex_.toString(); int pos = msg.indexOf("ORA-"); if (pos < 0) return -9999; pos += 4; ... |