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

booleanisReadOnlyException(SQLException e)
is Read Only Exception
return e.getErrorCode() == READ_ONLY_ERROR_CODE && e.getMessage().contains(READ_ONLY_ERROR_MESSAGE);
booleanisRecoverableException(SQLException e)
is Recoverable Exception
String sqlState = e.getSQLState();
if (sqlState != null && (sqlState.equals(SQL_STATE_DEADLOCK) || sqlState.equals(SQL_STATE_TIMEOUT)
        || sqlState.equals(SQL_STATE_IOERROR) || sqlState.equals(SQL_STATE_UNKNOWN))) {
    return true;
SQLException nextException = e.getNextException();
if (nextException != null && nextException != e) {
    return isRecoverableException(nextException);
...
booleanisTransient(SQLException e)
is Transient
return false;
booleanisXJ015Error(Throwable exception)
is XJ Error
while (exception != null) {
    if (exception instanceof SQLException && "XJ015".equals(((SQLException) exception).getSQLState())) {
        return true;
    exception = exception != exception.getCause() ? exception.getCause() : null;
return false;
voidlog(Logger logger, SQLException e)
Logback does not log exceptions associated to java.sql.SQLException#getNextException() .
SQLException next = e.getNextException();
while (next != null) {
    logger.error("SQL error: {}. Message: {}", next.getSQLState(), next.getMessage());
    next = next.getNextException();
voidlog(SQLException e, Logger log)
log
while (e != null) {
    log.debug(e.getMessage(), e);
    e = e.getNextException();
voidlogAll(Log log, SQLException e)
Log entire chain of SQLExceptions using old SQLException.getNextException interface instead of new Throwable.getCause().
logAll(log, null, e);
voidlogSqlError(SQLException ex, Logger logger)
log Sql Error
System.out.printf("DBERROR OCCURS: \n CODE-%d\n STATE: %s  MESSAGE: %s", +ex.getErrorCode(),
        ex.getSQLState(), ex.getMessage());
SQLExceptionmergeException(List exceptions)
merge Exception
SQLException first = exceptions.get(0);
List<StackTraceElement> stes = new ArrayList<StackTraceElement>(30 * exceptions.size());
for (StackTraceElement ste : first.getStackTrace()) {
    stes.add(ste);
Set<SQLException> exceptionsSet = new HashSet<SQLException>(exceptions.size());
exceptionsSet.add(first);
for (int i = 1, n = exceptions.size(); i < n; i++) {
...
SQLExceptionmergeException(List exceptions)
merge Exception
SQLException first = exceptions.get(0);
List<StackTraceElement> stes = new ArrayList<StackTraceElement>(30 * exceptions.size());
boolean hasSplit = false;
for (StackTraceElement ste : first.getStackTrace()) {
    stes.add(ste);
    if (ste == split) {
        hasSplit = true;
if (!hasSplit) {
    stes.add(split);
SQLException current = null;
for (int i = 1, n = exceptions.size(); i < n; i++) {
    current = exceptions.get(i);
    hasSplit = false;
    for (StackTraceElement ste : current.getStackTrace()) {
        stes.add(ste);
        if (ste == split) {
            hasSplit = true;
    if (!hasSplit) {
        stes.add(split);
first.setStackTrace(stes.toArray(new StackTraceElement[stes.size()]));
return first;