Java SQLException rollbackTransaction(final Connection conn, final SQLException e)

Here you can find the source of rollbackTransaction(final Connection conn, final SQLException e)

Description

Esegue un rollback della transazione.

License

Open Source License

Parameter

Parameter Description
conn connessione al db
e eccezione lanciata

Exception

Parameter Description
SQLException if a database access error occurs

Declaration

public static void rollbackTransaction(final Connection conn,
        final SQLException e) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.log4j.Logger;

public class Main {
    /** logger. */
    private static Logger logger;

    /**//from  w  w w.  j ava  2  s. c  o m
     * Esegue un rollback della transazione.
     * @param conn
     *            connessione al db
     * @param e
     *            eccezione lanciata
     * @throws SQLException
     *             if a database access error occurs
     */
    public static void rollbackTransaction(final Connection conn,
            final SQLException e) throws SQLException {
        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());
        }
    }
}

Related

  1. printSqlException(SQLException sqlex)
  2. printSQLExceptionToErrorLog(Log logger, String message, List sqlExceptions)
  3. printStackTrace(final Throwable exception)
  4. printStackTrace(SQLException e)
  5. retrieveDetailException(Throwable throwable)
  6. throwException(final Throwable t)
  7. throwException(String message)
  8. toSQLException(Throwable e)
  9. unboxException(SQLException exception)