Java Utililty Methods SQL Warning

List of utility methods to do SQL Warning

Description

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

Method

voidclearWarnings(Connection rawConnection)
clear Warnings
rawConnection.clearWarnings();
ThrowablegetCause(Throwable throwable)

Introspects the Throwable to obtain the cause.

The method searches for methods with specific names that return a Throwable object.

return getCause(throwable, CAUSE_METHOD_NAMES);
ThrowablegetCause(Throwable throwable)
get Cause
return getCause(throwable, CAUSE_METHOD_NAMES);
ThrowablegetCauseUsingWellKnownTypes(Throwable throwable)
get Cause Using Well Known Types
if (throwable instanceof SQLException) {
    return ((SQLException) throwable).getNextException();
} else if (throwable instanceof InvocationTargetException) {
    return ((InvocationTargetException) throwable).getTargetException();
} else {
    return null;
ThrowablegetCauseUsingWellKnownTypes(Throwable throwable)

Finds a Throwable for known types.

Uses instanceof checks to examine the exception, looking for well known types which could contain chained or wrapped exceptions.

if (throwable instanceof SQLException) {
    return ((SQLException) throwable).getNextException();
} else if (throwable instanceof InvocationTargetException) {
    return ((InvocationTargetException) throwable).getTargetException();
} else {
    return null;
ThrowablegetExceptionCauseUsingWellKnownTypes(final Throwable exception)
get Exception Cause Using Well Known Types
if (exception instanceof SQLException) {
    return ((SQLException) exception).getNextException();
} else if (exception instanceof InvocationTargetException) {
    return ((InvocationTargetException) exception).getTargetException();
} else {
    return null;
StringgetFullStackTrace(Throwable t)
get Full Stack Trace
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
Throwable[] ts = getThrowables(t);
for (Throwable t1 : ts) {
    t1.printStackTrace(pw);
    if (isNestedThrowable(t1)) {
        break;
return sw.getBuffer().toString();
ThrowablegetRootCause(Throwable throwable)

Walks through the exception chain to the last element -- the "root" of the tree -- using #getCause(Throwable) , and returns that exception.

Throwable cause = getCause(throwable);
if (cause != null) {
    throwable = cause;
    while ((throwable = getCause(throwable)) != null) {
        cause = throwable;
return cause;
...
String[]getRootCauseStackTrace(Throwable t)
Creates a compact stack trace for the root cause of the supplied throwable.
Throwable[] throwables = getThrowables(t);
int count = throwables.length;
ArrayList<String> frames = new ArrayList<String>();
List<String> nextTrace = getStackFrameList(throwables[count - 1]);
for (int i = count; --i >= 0;) {
    List<String> trace = nextTrace;
    if (i != 0) {
        nextTrace = getStackFrameList(throwables[i - 1]);
...
String[]getRootCauseStackTrace(Throwable throwable)

Creates a compact stack trace for the root cause of the supplied Throwable.

if (throwable == null) {
    return new String[0];
Throwable throwables[] = getThrowables(throwable);
int count = throwables.length;
ArrayList frames = new ArrayList();
List nextTrace = getStackFrameList(throwables[count - 1]);
for (int i = count; --i >= 0;) {
...