List of usage examples for java.sql SQLException getNextException
public SQLException getNextException()
SQLException
object by setNextException(SQLException ex). From source file:org.seasar.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute.java
protected void showContinueWarnLog(String sql, SQLException e) { final StringBuilder sb = new StringBuilder(); sb.append("*Failure: ").append(e.getClass().getName()).append(ln()); sb.append("/nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); sb.append(ln());/*from w w w . j a v a 2s . c o m*/ sb.append(extractMessage(e)).append(ln()); buildAdditionalErrorInfo(sb, e).append(ln()); final SQLException nextEx = e.getNextException(); if (nextEx != null) { sb.append("- - - - - - - - - -").append(ln()); sb.append(extractMessage(nextEx)).append(ln()); buildAdditionalErrorInfo(sb, nextEx).append(ln()); final SQLException nextNextEx = nextEx.getNextException(); if (nextNextEx != null) { sb.append("- - - - - - - - - -").append(ln()); sb.append(extractMessage(nextNextEx)).append(ln()); buildAdditionalErrorInfo(sb, nextNextEx).append(ln()); } } sb.append("nnnnnnnnnnnnnnnnnnnn/"); _log.warn(sb.toString()); }
From source file:org.apache.sqoop.connector.jdbc.GenericJdbcExecutor.java
private void logSQLException(SQLException e, String message) { LOG.error(message, e);/* ww w . ja va 2s. c o m*/ if (e.getNextException() != null) { logSQLException(e.getNextException(), "Caused by:"); } }
From source file:org.wso2.andes.store.rdbms.RDBMSStoreUtils.java
/** * Extract the vendor specific error code from a sql exception * //from w w w . ja va 2s . c o m * @param sqlException * the error * @return the error code supplied by the vendor */ private int extractErrorCode(SQLException sqlException) { int errorCode = sqlException.getErrorCode(); SQLException nextEx = sqlException.getNextException(); while (errorCode == 0 && nextEx != null) { errorCode = nextEx.getErrorCode(); nextEx = nextEx.getNextException(); } return errorCode; }
From source file:org.wso2.andes.store.rdbms.RDBMSStoreUtils.java
/** * Extracts SQL State from a given sql exception * //from w ww . ja v a2 s .c om * @param sqlException * the error * @return sql state */ private String extractSqlState(SQLException sqlException) { String sqlState = sqlException.getSQLState(); SQLException nextEx = sqlException.getNextException(); while (sqlState == null && nextEx != null) { sqlState = nextEx.getSQLState(); nextEx = nextEx.getNextException(); } return sqlState; }
From source file:org.rhq.enterprise.server.measurement.CallTimeDataManagerBean.java
private void logSQLException(String message, SQLException e) { SQLException mainException = e; StringBuilder causes = new StringBuilder(); int i = 1;//from w ww . ja v a 2 s .c om while ((e = e.getNextException()) != null) { causes.append(i++).append("\n\t").append(e); } log.error(message + " - causes: " + causes, mainException); }
From source file:com.xpn.xwiki.internal.store.hibernate.HibernateStore.java
/** * Hibernate and JDBC will wrap the exception thrown by the trigger in another exception (the * java.sql.BatchUpdateException) and this exception is sometimes wrapped again. Also the * java.sql.BatchUpdateException stores the underlying trigger exception in the nextException and not in the cause * property. The following method helps you to get to the underlying trigger message. *//*ww w. j a v a2 s . com*/ private String getExceptionMessage(Throwable t) { StringBuilder sb = new StringBuilder(); Throwable next = null; for (Throwable current = t; current != null; current = next) { next = current.getCause(); if (next == current) { next = null; } if (current instanceof SQLException) { SQLException sx = (SQLException) current; while (sx.getNextException() != null) { sx = sx.getNextException(); sb.append("\nSQL next exception = [" + sx + "]"); } } } return sb.toString(); }
From source file:gridool.db.catalog.DistributionCatalog.java
@Nonnull public int[] bindTableId(@Nonnull final String[] tableNames, @Nonnull final String templateTableNamePrefix) throws GridException { final int numTableNames = tableNames.length; if (numTableNames == 0) { return new int[0]; }/*from w ww .j a v a 2 s . c om*/ final int[] tableIds = new int[numTableNames]; Arrays.fill(tableIds, -1); final String insertQuery = "INSERT INTO \"" + partitionkeyTableName + "\"(tablename, tplprefix) VALUES(?, ?)"; final String selectQuery = "SELECT tablename, id FROM \"" + partitionkeyTableName + '"'; final ResultSetHandler rsh = new ResultSetHandler() { public Object handle(final ResultSet rs) throws SQLException { for (int i = 0; rs.next(); i++) { String tblname = rs.getString(1); int pos = ArrayUtils.indexOf(tableNames, tblname); if (pos != -1) { int key = rs.getInt(2); tableIds[pos] = key; } } return null; } }; final Object[][] params = new Object[numTableNames][]; for (int i = 0; i < numTableNames; i++) { params[i] = new Object[] { tableNames[i], templateTableNamePrefix }; } synchronized (tableIdMap) { final Connection conn = GridDbUtils.getPrimaryDbConnection(dbAccessor, false); try { JDBCUtils.batch(conn, insertQuery, params); JDBCUtils.query(conn, selectQuery, rsh); conn.commit(); } catch (SQLException e) { SQLException nexterr = e.getNextException(); if (nexterr == null) { LOG.error(e); } else { LOG.error(PrintUtils.prettyPrintStackTrace(nexterr), e); } try { conn.rollback(); } catch (SQLException rbe) { LOG.warn("Rollback failed", rbe); } throw new GridException(e); } finally { JDBCUtils.closeQuietly(conn); } for (int i = 0; i < numTableNames; i++) { String tblname = tableNames[i]; int tid = tableIds[i]; if (tid == -1) { throw new IllegalStateException("Table ID is not registered for table: " + tblname); } tableIdMap.put(tblname, tid); String templateTableName = templateTableNamePrefix + tblname; tableIdMap.put(templateTableName, tid); } } return tableIds; }
From source file:org.rhq.enterprise.server.event.EventManagerBean.java
public void addEventData(Map<EventSource, Set<Event>> events) { if (events == null || events.size() == 0) return;//from ww w . j a va 2 s.c om String statementSql; Connection conn = null; PreparedStatement ps = null; try { conn = rhqDs.getConnection(); DatabaseType dbType = DatabaseTypeFactory.getDatabaseType(conn); if (dbType instanceof PostgresqlDatabaseType || dbType instanceof OracleDatabaseType || dbType instanceof H2DatabaseType) { String nextvalSql = JDBCUtil.getNextValSql(conn, EventSource.TABLE_NAME); statementSql = String.format(EVENT_SOURCE_INSERT_STMT, nextvalSql); } else if (dbType instanceof SQLServerDatabaseType) { statementSql = EVENT_SOURCE_INSERT_STMT_AUTOINC; } else { throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType); } // First insert the "keys" (i.e. the EventSources). ps = conn.prepareStatement(statementSql); try { for (EventSource eventSource : events.keySet()) { int paramIndex = 1; ps.setString(paramIndex++, eventSource.getEventDefinition().getName()); ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getName()); ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getPlugin()); ps.setInt(paramIndex++, eventSource.getResource().getId()); ps.setString(paramIndex++, eventSource.getLocation()); ps.setString(paramIndex++, eventSource.getEventDefinition().getName()); ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getName()); ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getPlugin()); ps.setInt(paramIndex++, eventSource.getResource().getId()); ps.setString(paramIndex++, eventSource.getLocation()); ps.addBatch(); } ps.executeBatch(); } finally { JDBCUtil.safeClose(ps); } if (dbType instanceof PostgresqlDatabaseType || dbType instanceof OracleDatabaseType || dbType instanceof H2DatabaseType) { String nextvalSql = JDBCUtil.getNextValSql(conn, Event.TABLE_NAME); statementSql = String.format(EVENT_INSERT_STMT, nextvalSql); } else if (dbType instanceof SQLServerDatabaseType) { statementSql = EVENT_INSERT_STMT_AUTOINC; } else { throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType); } // Then insert the "values" (i.e. the Events). ps = conn.prepareStatement(statementSql); try { for (EventSource eventSource : events.keySet()) { Set<Event> eventData = events.get(eventSource); for (Event event : eventData) { int paramIndex = 1; ps.setString(paramIndex++, eventSource.getEventDefinition().getName()); ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getName()); ps.setString(paramIndex++, eventSource.getEventDefinition().getResourceType().getPlugin()); ps.setInt(paramIndex++, eventSource.getResource().getId()); ps.setString(paramIndex++, eventSource.getLocation()); ps.setLong(paramIndex++, event.getTimestamp()); ps.setString(paramIndex++, event.getSeverity().toString()); ps.setString(paramIndex++, event.getDetail()); ps.addBatch(); } notifyAlertConditionCacheManager("addEventData", eventSource, eventData.toArray(new Event[eventData.size()])); } ps.executeBatch(); } finally { JDBCUtil.safeClose(ps); } } catch (Throwable t) { // TODO what do we want to do here ? log.warn("addEventData: Insert of events failed : " + t.getMessage()); if (t instanceof SQLException) { SQLException e = (SQLException) t; Exception e2 = e.getNextException(); if (e2 != null) log.warn(" : " + e2.getMessage()); if (t.getCause() != null) log.warn(" : " + t.getCause().getMessage()); } } finally { JDBCUtil.safeClose(conn); } }
From source file:it.cnr.icar.eric.server.container.DerbyHelper.java
/** * Log appropriate information about a SQLException. In some cases, * the exception may be a normal consequence of connecting to the * shutdown URL. Logs something (message.stoppedDatabase at least) in * all cases.//from w w w .j ava 2 s. c om * * @param sqlException the {@link java.sql.SQLException} which should * be discarded (as normal) or logged */ protected void logDatabaseException(SQLException sqlException) { // In general, we do not know much about what these exceptions mean if (log.isDebugEnabled()) { while (null != sqlException) { // ??? add a message for unrecognized SQL exceptions log.error(sqlException); log.debug("Error Code: " + sqlException.getErrorCode()); log.debug("SQL State: " + sqlException.getSQLState()); sqlException = sqlException.getNextException(); } } else { // ??? add a message for unrecognized SQL exceptions log.error(sqlException); } }
From source file:org.apache.cayenne.log.CommonsJdbcEventLogger.java
@Override public void logQueryError(Throwable th) { if (isLoggable()) { if (th != null) { th = Util.unwindException(th); }//from w w w. jav a2s . c om logger.info("*** error.", th); if (th instanceof SQLException) { SQLException sqlException = ((SQLException) th).getNextException(); while (sqlException != null) { logger.info("*** nested SQL error.", sqlException); sqlException = sqlException.getNextException(); } } } }