Java Utililty Methods SQLException

List of utility methods to do SQLException

Description

The list of methods to do SQLException are organized into topic(s).

Method

ListappendToExceptionList(List list, SQLException sqlException)
append To Exception List
if (list == null) {
    list = new LinkedList<SQLException>();
list.add(sqlException);
return list;
StringconvertSQLExceptionToString(SQLException e)
convert SQL Exception To String
StringBuilder result = new StringBuilder(e.toString());
if (e.getNextException() != null) {
    result.append(" - causes:");
    SQLException cause = e;
    while ((cause = cause.getNextException()) != null) {
        result.append("\n\t").append(e);
return result.toString();
SQLExceptioncreateFeatureNotSupportedException()
create Feature Not Supported Exception
StackTraceElement ste = new Exception().getStackTrace()[1];
String methodName = ste.getMethodName();
return new SQLFeatureNotSupportedException(methodName + " is not supported"); 
StringexceptionMsg2LocalizedStr(final Throwable e)
exception Msg Localized Str
if (e == null)
    return null;
String message = e.getLocalizedMessage();
if (message == null)
    message = e.getClass().getName();
if (e instanceof SQLException) {
    SQLException nextException = ((SQLException) e).getNextException();
    if (nextException != null)
...
StringexceptionMsg2str(final Throwable e)
exception Msgstr
if (e == null)
    return null;
String message = e.getMessage();
if (message == null)
    message = e.getClass().getName();
if (e instanceof SQLException) {
    SQLException nextException = ((SQLException) e).getNextException();
    if (nextException != null)
...
StringexceptionToString(Throwable e)
exception To String
StringWriter writer = new StringWriter();
e.printStackTrace(new java.io.PrintWriter(writer));
return writer.toString().replace("" + (char) 0x00, "");
intextractErrorCode(SQLException sqlException)
For the given SQLException, locates the vendor-specific error code.
int errorCode = sqlException.getErrorCode();
SQLException nested = sqlException.getNextException();
while (errorCode == 0 && nested != null) {
    errorCode = nested.getErrorCode();
    nested = nested.getNextException();
return errorCode;
ListextractNestedSQLExceptions(SQLException exception)
extract Nested SQL Exceptions
List<Throwable> throwables = new ArrayList<Throwable>();
while (exception.getNextException() != null) {
    exception = exception.getNextException();
    throwables.add(exception);
return throwables;
StringextractSqlStateClassCode(SQLException sqlException)
For the given SQLException, locates the X/Open-compliant SQLState's class code.
return determineSqlStateClassCode(extractSqlState(sqlException));
StringgetAllMessages(Throwable t, boolean includeExceptionName)
Returns all the messages for the throwable and all of its causes in one long string.
StringBuffer ret_message = new StringBuffer();
if (t != null) {
    String[] msgs = getAllMessagesArray(t, includeExceptionName);
    ret_message.append(msgs[0]);
    for (int i = 1; i < msgs.length; i++) {
        ret_message.append(ARROW);
        ret_message.append(msgs[i]);
} else {
    ret_message.append(EXCEPTION_WAS_NULL);
return ret_message.toString();