Java Code Examples for java.sql.SQLException.getNextException()

The following are Jave code examples for showing how to use getNextException() of the java.sql.SQLException class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: SQLSyntaxErrorExceptionTests.java   View Source Code Vote up 7 votes
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLSyntaxErrorException ex = new SQLSyntaxErrorException("Exception 1", t1);
    SQLSyntaxErrorException ex1 = new SQLSyntaxErrorException("Exception 2");
    SQLSyntaxErrorException ex2 = new SQLSyntaxErrorException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 2
Project: openjdk-jdk10   File: SerialExceptionTests.java   View Source Code Vote up 6 votes
@Test
public void test04() {
    SQLException ex = new SerialException("Exception 1");
    ex.initCause(t1);
    SerialException ex1 = new SerialException("Exception 2");
    SerialException ex2 = new SerialException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
Example 3
Project: openjdk-jdk10   File: SQLNonTransientConnectionExceptionTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 4
Project: openjdk-jdk10   File: SQLExceptionTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLException ex = new SQLException("Exception 1", t1);
    SQLException ex1 = new SQLException("Exception 2");
    SQLException ex2 = new SQLException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
Example 5
Project: jdk8u-jdk   File: SyncProviderExceptionTests.java   View Source Code Vote up 6 votes
@Test
public void test06() {
    SQLException ex = new SyncProviderException("Exception 1");
    ex.initCause(t1);
    SyncProviderException ex1 = new SyncProviderException("Exception 2");
    SyncProviderException ex2 = new SyncProviderException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
Example 6
Project: openjdk-jdk10   File: SQLDataExceptionTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLDataException ex = new SQLDataException("Exception 1", t1);
    SQLDataException ex1 = new SQLDataException("Exception 2");
    SQLDataException ex2 = new SQLDataException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 7
Project: openjdk-jdk10   File: SyncProviderExceptionTests.java   View Source Code Vote up 6 votes
@Test
public void test06() {
    SQLException ex = new SyncProviderException("Exception 1");
    ex.initCause(t1);
    SyncProviderException ex1 = new SyncProviderException("Exception 2");
    SyncProviderException ex2 = new SyncProviderException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
Example 8
Project: jdk8u-jdk   File: SQLExceptionTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLException ex = new SQLException("Exception 1", t1);
    SQLException ex1 = new SQLException("Exception 2");
    SQLException ex2 = new SQLException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
Example 9
Project: jdk8u-jdk   File: SQLInvalidAuthorizationSpecExceptionTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    SQLInvalidAuthorizationSpecException ex
            = new SQLInvalidAuthorizationSpecException("Exception 1", t1);
    SQLInvalidAuthorizationSpecException ex1
            = new SQLInvalidAuthorizationSpecException("Exception 2");
    SQLInvalidAuthorizationSpecException ex2
            = new SQLInvalidAuthorizationSpecException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 10
Project: ats-framework   File: DbUtils.java   View Source Code Vote up 6 votes
/**
 * Adds single SQLException details and returns reference to the nested one
 * @param sqle
 * @param sb
 * @return
 */
private static SQLException addNestedSqlTrace(
                                               SQLException sqle,
                                               StringBuilder sb ) {

    sb.append("SQL Exception:");
    sb.append("\n\tMessage: ").append(sqle.getMessage());
    sb.append("\n\tSQL state: ").append(sqle.getSQLState());
    sb.append("\n\tVendor code: ").append(sqle.getErrorCode());
    StringWriter stringWriter = new StringWriter();
    sqle.printStackTrace(new PrintWriter(stringWriter));
    sb.append(stringWriter.toString());
    sb.append("\n----------------------------------------\n");

    return sqle.getNextException();
}
 
Example 11
Project: jdk8u-jdk   File: SQLTransientConnectionExceptionTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLTransientConnectionException ex =
            new SQLTransientConnectionException("Exception 1", t1);
    SQLTransientConnectionException ex1 =
            new SQLTransientConnectionException("Exception 2");
    SQLTransientConnectionException ex2 =
            new SQLTransientConnectionException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 12
Project: jdk8u-jdk   File: SyncFactoryExceptionTests.java   View Source Code Vote up 6 votes
@Test
public void test04() {
    SQLException ex = new SyncFactoryException("Exception 1");
    ex.initCause(t1);
    SyncFactoryException ex1 = new SyncFactoryException("Exception 2");
    SyncFactoryException ex2 = new SyncFactoryException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
 
Example 13
Project: jdk8u-jdk   File: SQLWarningTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    SQLWarning ex = new SQLWarning("Exception 1", t1);
    SQLWarning ex1 = new SQLWarning("Exception 2");
    SQLWarning ex2 = new SQLWarning("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 14
Project: openjdk-jdk10   File: SQLIntegrityConstraintViolationExceptionTests.java   View Source Code Vote up 6 votes
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 15
Project: calcite-avatica   File: Service.java   View Source Code Vote up 5 votes
static List<String> toStackTraces(Exception e) {
  List<String> stackTraces = new ArrayList<>();
  stackTraces.add(toString(e));
  if (e instanceof SQLException) {
    SQLException next = ((SQLException) e).getNextException();
    while (null != next) {
      stackTraces.add(toString(next));
      next = next.getNextException();
    }
  }
  return stackTraces;
}
 
Example 16
Project: DBus   File: LoggingUtils.java   View Source Code Vote up 5 votes
public static void logAll(Logger log, String message, SQLException e) {
  log.error(message == null ? "Top level exception: " : message, e);
  e = e.getNextException();
  int indx = 1;
  while (e != null) {
    log.error("Chained exception " + indx + ": ", e);
    e = e.getNextException();
    indx++;
  }
}
 
Example 17
Project: ats-framework   File: DatabaseAccessException.java   View Source Code Vote up 5 votes
private SQLException printStackTrace( SQLException sqle ) {

        log.error("SQL Exception:\nMessage: " + sqle.getMessage() + "\nSQL state: "
                  + sqle.getSQLState() + "\nVendor code: " + sqle.getErrorCode());
        sqle.printStackTrace();
        log.error("------------------------------------------------");

        return sqle.getNextException();
    }
 
Example 18
Project: lams   File: SQLStateSQLExceptionTranslator.java   View Source Code Vote up 5 votes
/**
 * Gets the SQL state code from the supplied {@link SQLException exception}.
 * <p>Some JDBC drivers nest the actual exception from a batched update, so we
 * might need to dig down into the nested exception.
 * @param ex the exception from which the {@link SQLException#getSQLState() SQL state}
 * is to be extracted
 * @return the SQL state code
 */
private String getSqlState(SQLException ex) {
	String sqlState = ex.getSQLState();
	if (sqlState == null) {
		SQLException nestedEx = ex.getNextException();
		if (nestedEx != null) {
			sqlState = nestedEx.getSQLState();
		}
	}
	return sqlState;
}
 
Example 19
Project: parabuild-ci   File: JDBCExceptionHelper.java   View Source Code Vote up 5 votes
/**
 * For the given SQLException, locates the X/Open-compliant SQLState.
 *
 * @param sqlException The exception from which to extract the SQLState
 * @return The SQLState code, or null.
 */
public static String extractSqlState(SQLException sqlException) {
	String sqlState = sqlException.getSQLState();
	SQLException nested = sqlException.getNextException();
	while( sqlState == null && nested != null) {
		sqlState = nested.getSQLState();
		nested = nested.getNextException();
	}
	return sqlState;
}
 
Example 20
Project: uroborosql   File: SqlAgentImpl.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 *
 * @see jp.co.future.uroborosql.AbstractAgent#handleException(jp.co.future.uroborosql.context.SqlContext,
 *      java.sql.SQLException)
 */
@Override
protected void handleException(final SqlContext sqlContext, final SQLException ex) throws SQLException {
	SQLException cause = ex;

	while (cause.getNextException() != null) {
		cause = cause.getNextException();
	}

	if (LOG.isErrorEnabled() && isOutputExceptionLog()) {
		StringBuilder builder = new StringBuilder();
		builder.append(System.lineSeparator()).append("Exception occurred in SQL execution.")
				.append(System.lineSeparator());
		builder.append("Executed SQL[").append(sqlContext.getExecutableSql()).append("]")
				.append(System.lineSeparator());
		if (sqlContext instanceof SqlContextImpl) {
			Parameter[] bindParameters = ((SqlContextImpl) sqlContext).getBindParameters();
			for (int i = 0; i < bindParameters.length; i++) {
				Parameter parameter = getSqlFilterManager().doParameter(bindParameters[i]);
				builder.append("Bind Parameter.[INDEX[").append(i + 1).append("], ").append(parameter.toString())
						.append("]").append(System.lineSeparator());
			}
		}
		LOG.error(builder.toString(), cause);
	}

	throw cause;
}