Java Code Examples for java.sql.SQLException#getNextException()
The following examples show how to use
java.sql.SQLException#getNextException() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleApp.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Prints details of an SQLException chain to <code>System.err</code>. * Details included are SQL State, Error code, Exception message. * * @param e the SQLException from which to print details. */ public static void printSQLException(SQLException e) { // Unwraps the entire exception chain to unveil the real cause of the // 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()); // for stack traces, refer to gemfirexd.log or uncomment this: //e.printStackTrace(System.err); e = e.getNextException(); } }
Example 2
Source File: SQLSyntaxErrorExceptionTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 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 3
Source File: SQLNonTransientConnectionExceptionTests.java From hottub with GNU General Public License v2.0 | 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
Source File: DBTestBase.java From netbeans with Apache License 2.0 | 6 votes |
/** * Goes through all SQLExceptions found through getNextException() * and builds it instead as a set of chained exceptions, so they * all get reported */ protected static SQLException processSQLException(SQLException original) { SQLException next = original; while (next != null) { if (next.getNextException() != null) { Throwable cause = next; while (cause.getCause() != null) { cause = cause.getCause(); } cause.initCause(next.getNextException()); } next = next.getNextException(); } return original; }
Example 5
Source File: SyncFactoryExceptionTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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 6
Source File: SQLRecoverableExceptionTests.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Validate that the ordering of the returned Exceptions is correct * using traditional while loop */ @Test public void test12() { SQLRecoverableException ex = new SQLRecoverableException("Exception 1", t1); SQLRecoverableException ex1 = new SQLRecoverableException("Exception 2"); SQLRecoverableException ex2 = new SQLRecoverableException("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
Source File: SQLClientInfoExceptionTests.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Validate that the ordering of the returned Exceptions is correct using * traditional while loop */ @Test public void test12() { SQLClientInfoException ex = new SQLClientInfoException("Exception 1", map, t1); SQLClientInfoException ex1 = new SQLClientInfoException("Exception 2", map); SQLClientInfoException ex2 = new SQLClientInfoException("Exception 3", map, 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 8
Source File: SQLFeatureNotSupportedExceptionTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Validate that the ordering of the returned Exceptions is correct * using traditional while loop */ @Test public void test12() { SQLFeatureNotSupportedException ex = new SQLFeatureNotSupportedException("Exception 1", t1); SQLFeatureNotSupportedException ex1 = new SQLFeatureNotSupportedException("Exception 2"); SQLFeatureNotSupportedException ex2 = new SQLFeatureNotSupportedException("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 9
Source File: SQLTransactionRollbackExceptionTests.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Validate that the ordering of the returned Exceptions is correct * using traditional while loop */ @Test public void test12() { SQLTransactionRollbackException ex = new SQLTransactionRollbackException("Exception 1", t1); SQLTransactionRollbackException ex1 = new SQLTransactionRollbackException("Exception 2"); SQLTransactionRollbackException ex2 = new SQLTransactionRollbackException("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
Source File: RowSetWarningTests.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Test public void test07() { RowSetWarning ex = new RowSetWarning("Exception 1"); ex.initCause(t1); RowSetWarning ex1 = new RowSetWarning("Exception 2"); RowSetWarning ex2 = new RowSetWarning("Exception 3"); ex2.initCause(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 11
Source File: SQLTransientConnectionExceptionTests.java From openjdk-jdk9 with GNU General Public License v2.0 | 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
Source File: SQLTimeoutExceptionTests.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Validate that the ordering of the returned Exceptions is correct * using traditional while loop */ @Test public void test12() { SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1); SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2"); SQLTimeoutException ex2 = new SQLTimeoutException("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 13
Source File: SQLNonTransientExceptionTests.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Validate that the ordering of the returned Exceptions is correct * using traditional while loop */ @Test public void test12() { SQLNonTransientException ex = new SQLNonTransientException("Exception 1", t1); SQLNonTransientException ex1 = new SQLNonTransientException("Exception 2"); SQLNonTransientException ex2 = new SQLNonTransientException("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
Source File: ResultSetStreamTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void assertMisMatchStreamLength(SQLException sqle) { if (usingEmbedded()) { assertEquals("XSDA4",sqle.getSQLState()); sqle = sqle.getNextException(); assertSQLState("XJ001",sqle); } else { String state = sqle.getSQLState(); assertTrue("SQLState not XN015 or XN017 as expected", "XN015".equals(state) || "XN017".equals(state)); } }
Example 15
Source File: SQLStateSQLExceptionTranslator.java From spring4-understanding with Apache License 2.0 | 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 16
Source File: SectDBSynchronizer.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
protected void writeExceptionInErrorXML(SQLException sqle, int indent, final int indentStep, boolean printStack) throws XMLStreamException { indentInErrorXML(indent); this.errorWriter.writeStartElement(ERR_XML_EXCEPTION); indent += indentStep; writeObjectInErrorXML(ERR_XML_SQLSTATE, sqle.getSQLState(), indent); writeObjectInErrorXML(ERR_XML_ERRCODE, sqle.getErrorCode(), indent); writeObjectInErrorXML(ERR_XML_EX_MESSAGE, sqle.getMessage(), indent); if (printStack) { StringBuilder sb = new StringBuilder(); helper.getStackTrace(sqle, sb); writeObjectInErrorXML(ERR_XML_EX_STACK, sb.toString(), indent); } else { writeObjectInErrorXML(ERR_XML_EX_STACK, sqle.toString(), indent); } if ((sqle = sqle.getNextException()) != null) { writeExceptionInErrorXML(sqle, indent, indentStep, false); } indent -= indentStep; indentInErrorXML(indent); this.errorWriter.writeEndElement(); }
Example 17
Source File: closed.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void run() { try { cc.createStatement().execute(sql); result = "Sleep thread completed " + sql; } catch (SQLException sqle) { // this is to avoid different cannons for different JVMs since // an java.lang.InterruptedException is thrown. StringBuilder sb = new StringBuilder(); sb.append(sql); sb.append(" - "); sb.append(sqle.getSQLState()); while (sqle != null) { if (sqle != null) { sb.append(", "); sb.append(sqle.getSQLState()); sb.append(" -- "); if (sqle.getMessage().indexOf("InterruptedException") != -1) sb.append("InterruptedException"); else { sb.append(sqle.getMessage()); sqle.printStackTrace(System.out); } } else { sb.append(sqle.getMessage()); } sqle = sqle.getNextException(); } result = sb.toString(); } }
Example 18
Source File: BaseJDBCTestCase.java From kareldb with Apache License 2.0 | 5 votes |
/** * Assert that SQLState is as expected. If the SQLState for * the top-level exception doesn't match, look for nested * exceptions and, if there are any, see if they have the * desired SQLState. * * @param message message to print on failure. * @param expected the expected SQLState. * @param exception the exception to check the SQLState of. */ public static void assertSQLState(String message, String expected, SQLException exception) { // Make sure exception is not null. We want to separate between a // null-exception object, and a null-SQLState. assertNotNull("Exception cannot be null when asserting on SQLState", exception); try { String state = exception.getSQLState(); if (state != null) assertTrue("The exception's SQL state must be five characters long", state.length() == 5); if (expected != null) assertTrue("The expected SQL state must be five characters long", expected.length() == 5); assertEquals(message, expected, state); } catch (AssertionFailedError e) { // Save the SQLException e.initCause(exception); // Check nested exceptions to see if any of them is // the one we're looking for. exception = exception.getNextException(); if (exception != null) assertSQLState(message, expected, exception); else throw e; } }
Example 19
Source File: MySQLDataStore.java From boon with Apache License 2.0 | 4 votes |
public void handleSQLException(Throwable ex) { if (ex instanceof SQLException) { SQLException sqlException = (SQLException) ex; SQLException next = sqlException.getNextException(); while (next != null) { logger.error(next, "MySQLDataStore Nested SQL Exception", next.getMessage()); next = sqlException.getNextException(); } } else { handleSQLException(ex.getCause()); } }
Example 20
Source File: LangProcedureTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void sqlControl4(int sqlc, String[] e1, String[] e2, String[] e3, String[] e4, String[] e5, String[] e6, String[] e7, String[] e8) throws SQLException { Connection conn = DriverManager .getConnection("jdbc:default:connection"); String sql = "CALL SQLC.SQLCONTROL2_" + sqlc + " (?, ?, ?, ?, ?, ?, ?) "; e1[0] = sql; CallableStatement cs1 = conn.prepareCall(sql); try { for (int rop = 1; rop <= 7; rop++) { cs1.registerOutParameter(rop, Types.VARCHAR); } cs1.execute(); e2[0] = cs1.getString(1); e3[0] = cs1.getString(2); e4[0] = cs1.getString(3); e5[0] = cs1.getString(4); e6[0] = cs1.getString(5); e7[0] = cs1.getString(6); e8[0] = cs1.getString(7); } catch (SQLException sqle) { StringBuilder sb = new StringBuilder(128); sb.append("STATE"); do { sb.append("-"); String ss = sqle.getSQLState(); if (ss == null) ss = "?????"; sb.append(ss); sqle = sqle.getNextException(); } while (sqle != null); e2[0] = sb.toString(); } cs1.close(); conn.close(); }