本文整理了Java中java.sql.SQLException.getNextException()
方法的一些代码示例,展示了SQLException.getNextException()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException.getNextException()
方法的具体详情如下:
包路径:java.sql.SQLException
类名称:SQLException
方法名:getNextException
[英]Retrieves the SQLException chained to this SQLException, if any.
[中]检索链接到此SQLException的SQLException(如果有)。
代码示例来源:origin: spring-projects/spring-framework
/**
* 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
*/
@Nullable
private String getSqlState(SQLException ex) {
String sqlState = ex.getSQLState();
if (sqlState == null) {
SQLException nestedEx = ex.getNextException();
if (nestedEx != null) {
sqlState = nestedEx.getSQLState();
}
}
return sqlState;
}
代码示例来源:origin: apache/ignite
/**
* @param throwable The exception to examine.
* @return The wrapped exception, or {@code null} if not found.
*/
private static Throwable getCauseUsingWellKnownTypes(Throwable throwable) {
if (throwable instanceof SQLException)
return ((SQLException)throwable).getNextException();
if (throwable instanceof InvocationTargetException)
return ((InvocationTargetException)throwable).getTargetException();
return null;
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* 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;
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* For the given SQLException, locates the vendor-specific error code.
*
* @param sqlException The exception from which to extract the SQLState
* @return The error code.
*/
public static int extractErrorCode(SQLException sqlException) {
int errorCode = sqlException.getErrorCode();
SQLException nested = sqlException.getNextException();
while ( errorCode == 0 && nested != null ) {
errorCode = nested.getErrorCode();
nested = nested.getNextException();
}
return errorCode;
}
代码示例来源:origin: apache/activemq
public static void log(String msg, SQLException e) {
String s = msg + e.getMessage();
while (e.getNextException() != null) {
e = e.getNextException();
s += ", due to: " + e.getMessage();
}
LOG.warn(s, e);
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Logback does not log exceptions associated to {@link java.sql.SQLException#getNextException()}.
* See http://jira.qos.ch/browse/LOGBACK-775
*/
public static void log(Logger logger, SQLException e) {
SQLException next = e.getNextException();
while (next != null) {
logger.error("SQL error: {}. Message: {}", next.getSQLState(), next.getMessage());
next = next.getNextException();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public String extractConstraintName(SQLException sqle) {
try {
String constraintName = null;
// handle nested exceptions
do {
constraintName = doExtractConstraintName(sqle);
if (sqle.getNextException() == null
|| sqle.getNextException() == sqle) {
break;
}
else {
sqle = sqle.getNextException();
}
} while (constraintName == null);
return constraintName;
}
catch (NumberFormatException nfe) {
return null;
}
}
代码示例来源:origin: robovm/robovm
/**
* Gets the next {@code SQLWarning} chained to this {@code SQLWarning} object.
*
* @return the {@code SQLWarning} chained to this {@code SQLWarning}.
* {@code null} if no {@code SQLWarning} is chained to this {@code
* SQLWarning}.
*/
public SQLWarning getNextWarning() {
SQLException next = super.getNextException();
if (next == null) {
return null;
}
if (next instanceof SQLWarning) {
return (SQLWarning) next;
}
throw new Error("SQLWarning chain holds value that is not a SQLWarning");
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* <p>
* Uses <code>instanceof</code> checks to examine the exception, looking for well known types which could contain
* chained or wrapped exceptions.
* </p>
*
* @param throwable the exception to examine
* @return The wrapped exception, or <code>null</code> if not found.
*/
private static Throwable getCauseUsingWellKnownTypes( Throwable throwable )
{
if ( throwable instanceof SQLException )
{
return ( (SQLException) throwable ).getNextException();
}
else if ( throwable instanceof InvocationTargetException )
{
return ( (InvocationTargetException) throwable ).getTargetException();
}
else
{
return null;
}
}
代码示例来源:origin: jdbi/jdbi
/**
* SQLExceptions thrown from batch executions have errors
* in a {@link SQLException#getNextException()} chain, which
* doesn't print out when you log them. Convert them to be
* {@link Throwable#addSuppressed(Throwable)} exceptions,
* which do print out with common logging frameworks.
*
* @param e the exception
* @return the 'suppressed' munged exception change
*/
static SQLException mungeBatchException(SQLException e) {
for (SQLException next = e.getNextException(); next != null; next = next.getNextException()) {
e.addSuppressed(next);
}
return e;
}
}
代码示例来源:origin: commons-lang/commons-lang
/**
* <p>Finds a <code>Throwable</code> for known types.</p>
*
* <p>Uses <code>instanceof</code> checks to examine the exception,
* looking for well known types which could contain chained or
* wrapped exceptions.</p>
*
* @param throwable the exception to examine
* @return the wrapped exception, or <code>null</code> if not found
*/
private static Throwable getCauseUsingWellKnownTypes(Throwable throwable) {
if (throwable instanceof Nestable) {
return ((Nestable) throwable).getCause();
} else if (throwable instanceof SQLException) {
return ((SQLException) throwable).getNextException();
} else if (throwable instanceof InvocationTargetException) {
return ((InvocationTargetException) throwable).getTargetException();
} else {
return null;
}
}
代码示例来源:origin: com.h2database/h2
/**
* Prints the stack trace to the specified print stream.
*
* @param s the print stream
*/
@Override
public void printStackTrace(PrintStream s) {
if (s != null) {
super.printStackTrace(s);
// getNextException().printStackTrace(s) would be very very slow
// if many exceptions are joined
SQLException next = getNextException();
for (int i = 0; i < 100 && next != null; i++) {
s.println(next.toString());
next = next.getNextException();
}
if (next != null) {
s.println("(truncated)");
}
}
}
代码示例来源:origin: com.h2database/h2
/**
* Prints the stack trace to the specified print writer.
*
* @param s the print writer
*/
@Override
public void printStackTrace(PrintWriter s) {
if (s != null) {
super.printStackTrace(s);
// getNextException().printStackTrace(s) would be very very slow
// if many exceptions are joined
SQLException next = getNextException();
for (int i = 0; i < 100 && next != null; i++) {
s.println(next.toString());
next = next.getNextException();
}
if (next != null) {
s.println("(truncated)");
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public void printSQLException( SQLException ex ) {
log.logError( "==> SQLException: " );
while ( ex != null ) {
log.logError( "Message: " + ex.getMessage() );
log.logError( "SQLState: " + ex.getSQLState() );
log.logError( "ErrorCode: " + ex.getErrorCode() );
ex = ex.getNextException();
log.logError( "" );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static KettleDatabaseBatchException createKettleDatabaseBatchException( String message, SQLException ex ) {
KettleDatabaseBatchException kdbe = new KettleDatabaseBatchException( message, ex );
if ( ex instanceof BatchUpdateException ) {
kdbe.setUpdateCounts( ( (BatchUpdateException) ex ).getUpdateCounts() );
} else {
// Null update count forces rollback of batch
kdbe.setUpdateCounts( null );
}
List<Exception> exceptions = new ArrayList<Exception>();
SQLException nextException = ex.getNextException();
SQLException oldException = null;
// This construction is specifically done for some JDBC drivers, these
// drivers
// always return the same exception on getNextException() (and thus go
// into an infinite loop).
// So it's not "equals" but != (comments from Sven Boden).
while ( ( nextException != null ) && ( oldException != nextException ) ) {
exceptions.add( nextException );
oldException = nextException;
nextException = nextException.getNextException();
}
kdbe.setExceptionsList( exceptions );
return kdbe;
}
代码示例来源:origin: SonarSource/sonarqube
public void executeUpdateSql(String sql, Object... params) {
try (Connection connection = getConnection()) {
new QueryRunner().update(connection, sql, params);
if (!connection.getAutoCommit()) {
connection.commit();
}
} catch (SQLException e) {
SQLException nextException = e.getNextException();
if (nextException != null) {
throw new IllegalStateException("Fail to execute sql: " + sql,
new SQLException(e.getMessage(), nextException.getSQLState(), nextException.getErrorCode(), nextException));
}
throw new IllegalStateException("Fail to execute sql: " + sql, e);
} catch (Exception e) {
throw new IllegalStateException("Fail to execute sql: " + sql, e);
}
}
代码示例来源:origin: jdbi/jdbi
private void assertSuppressions(Throwable cause) {
LoggerFactory.getLogger(TestBatchExceptionRewrite.class).info("exception", cause);
SQLException e = (SQLException) cause;
SQLException nextException = e.getNextException();
assertThat((Exception) nextException).isEqualTo(e.getSuppressed()[0]);
assertThat((Exception) nextException.getNextException()).isNull();
assertThat(e.getSuppressed()).hasSize(1);
}
}
代码示例来源:origin: spring-projects/spring-framework
protected DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex) {
SQLException sqlEx = ex;
if (sqlEx instanceof BatchUpdateException && sqlEx.getNextException() != null) {
SQLException nestedSqlEx = sqlEx.getNextException();
if (nestedSqlEx.getErrorCode() > 0 || nestedSqlEx.getSQLState() != null) {
logger.debug("Using nested SQLException from the BatchUpdateException");
代码示例来源:origin: org.postgresql/postgresql
public void handleCompletion() throws SQLException {
updateGeneratedKeys();
SQLException batchException = getException();
if (batchException != null) {
if (isAutoCommit()) {
// Re-create batch exception since rows after exception might indeed succeed.
BatchUpdateException newException = new BatchUpdateException(
batchException.getMessage(),
batchException.getSQLState(),
uncompressUpdateCount()
);
newException.initCause(batchException.getCause());
SQLException next = batchException.getNextException();
if (next != null) {
newException.setNextException(next);
}
batchException = newException;
}
throw batchException;
}
}
代码示例来源:origin: hibernate/hibernate-orm
System.err.println( e.getSQLException().getNextException() );
内容来源于网络,如有侵权,请联系作者删除!