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

voidmergeSQLExceptionMsg(final StringBuilder msgBuilder, final SQLException e, final String prefix)
merge SQL Exception Msg
msgBuilder.append(prefix + "ErrorCode: ");
msgBuilder.append(e.getErrorCode());
msgBuilder.append(", SQLState: ");
msgBuilder.append(e.getSQLState());
msgBuilder.append(", Msg: ");
String m = e.getMessage();
if (m != null) {
    msgBuilder.append(prefix + m.replaceAll("\n", "\n" + prefix));
...
booleanoracleSessionHasBeenKilled(Exception exception)
oracle Session Has Been Killed
Throwable ex = exception;
while (ex != null) {
    if (ex instanceof SQLException && ((SQLException) ex).getErrorCode() == 28) 
        return true;
    ex = ex.getCause();
return false;
SQLExceptionparseRemoteException(Throwable t)
parse Remote Exception
String message = t.getLocalizedMessage();
if (message != null) {
    Matcher matcher = PATTERN.matcher(t.getLocalizedMessage());
    if (matcher.find()) {
        int errorCode = Integer.parseInt(matcher.group(1));
        String sqlState = matcher.group(2);
        return new SQLException(matcher.group(), sqlState, errorCode, t);
return null;
voidprintExceptionAndRollback(Connection conn, Exception e)
print Exception And Rollback
printException(e);
try {
    if (conn != null)
        conn.rollback();
} catch (SQLException ignore) {
voidprintExceptions(OutputStream os, SQLException sqlEx)
Print an exception, or series of exceptions to the designated output stream.
PrintWriter pw = new PrintWriter(os, true);
while (sqlEx != null) {
    pw.println("----------------------------------------------");
    pw.println("ERROR CODE : " + sqlEx.getErrorCode());
    pw.println("ERROR STATE: " + sqlEx.getSQLState());
    sqlEx.printStackTrace(pw);
    sqlEx = sqlEx.getNextException();
voidprintSQLException(SQLException e)
print SQL Exception
while (e != null) {
    System.err.println("\n----- SQLException -----");
    System.err.println("  SQL State:  " + e.getSQLState());
    System.err.println("  Error Code: " + e.getErrorCode());
    System.err.println("  Message:    " + e.getMessage());
    e = e.getNextException();
voidprintSQLException(SQLException e)
print SQL Exception
String format = "%-12s : %s\n";
while (e != null) {
    String errMsg = "------------- SQLException ----------------\n";
    errMsg += String.format(format, "SQL State", e.getSQLState());
    errMsg += String.format(format, "Error Code", e.getErrorCode());
    errMsg += String.format(format, "Cause", e.getCause());
    errMsg += String.format(format, "Message", e.getMessage());
    System.err.print(errMsg);
...
voidprintSQLException(SQLException ex)
print SQL Exception
for (Throwable e : ex) {
    if (e instanceof SQLException) {
        if (ignoreSQLException(((SQLException) e).getSQLState()) == false) {
            e.printStackTrace(System.err);
            System.err.println("SQLState: " + ((SQLException) e).getSQLState());
            System.err.println("Error Code: " + ((SQLException) e).getErrorCode());
            System.err.println("Message: " + e.getMessage());
            Throwable t = ex.getCause();
...
voidprintSQLException(SQLException ex)
print SQL Exception
for (Throwable e : ex) {
    if (e instanceof SQLException) {
        e.printStackTrace(System.err);
        System.err.println("SQLState: " + ((SQLException) e).getSQLState());
        System.err.println("Error Code: " + ((SQLException) e).getErrorCode());
        System.err.println("Message: " + e.getMessage());
        Throwable t = ex.getCause();
        while (t != null) {
...
StringprintSqlException(SQLException sqlex)
print Sql Exception
StringBuffer sb = new StringBuffer();
sb.append("SQLException:\n");
while (sqlex != null) {
    sb.append(sqlex.getMessage() + "\n");
    sb.append("SQL State: " + sqlex.getSQLState() + "\n");
    sb.append("Vendor Error Code: " + sqlex.getErrorCode() + "\n");
    sqlex = sqlex.getNextException();
return sb.toString();