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

voidprintSQLExceptionToErrorLog(Log logger, String message, List sqlExceptions)
print SQL Exception To Error Log
if (sqlExceptions != null && !sqlExceptions.isEmpty()) {
    for (SQLException sqlException : sqlExceptions) {
        logger.error(message, sqlException);
    sqlExceptions.clear();
voidprintStackTrace(final Throwable exception)
print Stack Trace
printStackTrace(exception, null);
voidprintStackTrace(SQLException e)
Print the stack trace for a SQLException to STDERR.
printStackTrace(e, new PrintWriter(System.err));
SQLExceptionretrieveDetailException(Throwable throwable)
Returns an instance of SQLException containing detailed error information
String lineSep = System.getProperty("line.separator");
if (throwable != null) {
    StringBuffer msg = new StringBuffer("");
    if (throwable.getLocalizedMessage() != null) {
        msg.append(throwable.getLocalizedMessage());
    } else {
        msg.append(throwable.getMessage());
    if (throwable instanceof SQLException) {
        SQLException sqlEx = (SQLException) throwable;
        while (sqlEx.getNextException() != null) {
            sqlEx = sqlEx.getNextException();
            if (sqlEx.getLocalizedMessage() != null) {
                msg.append("").append(lineSep).append(sqlEx.getLocalizedMessage());
            } else {
                msg.append("").append(lineSep).append(sqlEx.getMessage());
    return new SQLException(msg.toString());
return null;
voidrollbackTransaction(final Connection conn, final SQLException e)
Esegue un rollback della transazione.
if (conn != null) {
    conn.rollback();
    logger.fatal("Connection rollback...");
    logger.fatal(e.getStackTrace());
    StringWriter sWriter = new StringWriter();
    e.printStackTrace(new PrintWriter(sWriter));
    logger.fatal(sWriter.getBuffer().toString());
voidthrowException(final Throwable t)
Examine a Throwable to preserve RuntimeException and Error, otherwise throw a SQLException.
throwException(t, null);
SQLExceptionthrowException(String message)
throw Exception
throw new SQLException(message, "FULLTEXT");
SQLExceptiontoSQLException(Throwable e)
convert Throwable to SQLException
SQLException se = new SQLException(e.getMessage());
se.setStackTrace(e.getStackTrace());
se.printStackTrace();
return se;
SQLExceptionunboxException(SQLException exception)
unbox Exception
final Throwable cause = exception.getCause();
if (cause == null || !(cause instanceof RuntimeException)) {
    return exception;
SQLException unboxed = new SQLException(exception.getMessage());
unboxed.setStackTrace(exception.getStackTrace());
return unboxed;