Looks for SQLException in the cause chain.

@return Found SQLException in the cause chain, or null if none found
189924
public static SQLException unwrapSQLException(Throwable throwable) {
        if (throwable == null) {
            return null;
        } else if (throwable instanceof SQLException) {
            return (SQLException) throwable;
        } else if (throwable.getCause() != null) {
            // recursive call to unwrap the cause
            return unwrapSQLException(throwable.getCause());
        } else {
            // didn't find any SQLException in the cause stack
            return null;
        }
    }
228792
public Object firstRow() throws SQLException {
        List rows = rows();
        if (rows.isEmpty()) return null;
        return (rows.get(0));
    }
230698
public SQLException exceptionWithQuery(String sql, SQLException sqlException,
      boolean explicitClosed) {
    if (explicitClosed) {
      return new SQLException(
          "Connection has explicitly been closed/aborted.\nQuery is: " + subQuery(sql),
          sqlException.getSQLState(),
          sqlException.getErrorCode(), sqlException.getCause());
    }

    if (options.dumpQueriesOnException || sqlException.getErrorCode() == 1064) {
      return new SQLException(sqlException.getMessage()
          + "\nQuery is: " + subQuery(sql)
          + "\njava thread: " + Thread.currentThread().getName(),
          sqlException.getSQLState(),
          sqlException.getErrorCode(), sqlException.getCause());
    }
    return sqlException;
  }
108259
public int delete() throws SQLException {
		checkForDao();
		@SuppressWarnings("unchecked")
		T t = (T) this;
		return dao.delete(t);
	}
810830
public int[] executeBatch() throws SQLException {
        final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
        SQLExecuteCallback<int[]> callback = new SQLExecuteCallback<int[]>(getDatabaseType(), isExceptionThrown) {
            
            @Override
            protected int[] executeSQL(final RouteUnit routeUnit, final Statement statement, final ConnectionMode connectionMode) throws SQLException {
                return statement.executeBatch();
            }
        };
        List<int[]> results = executeCallback(callback);
        if (isAccumulate()) {
            return accumulate(results);
        } else {
            return results.get(0);
        }
    }
371824
public boolean hasNext()
	{
		try {
			if (result != null && result.next()) {
				return true;
			}

			if (this.statement != null) {
				this.statement.close();
			}
			if (this.result != null) {
				this.result.close();
			}

			return query();

		}
		catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
611657
public String sql() {
        if (sb == null) {
            throw new AbacusException("This SQLBuilder has been closed after sql() was called previously");
        }

        init(true);

        String sql = null;

        try {
            sql = sb.toString();
        } finally {
            Objectory.recycle(sb);
            sb = null;

            activeStringBuilderCounter.decrementAndGet();
        }

        if (logger.isDebugEnabled()) {
            logger.debug(sql);
        }

        return sql;
    }
133432
public boolean isAnAuthorizationException(SQLException x) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(this, tc, "isAnAuthorizationException", x);

        boolean isAuthError = false;
        LinkedList<SQLException> stack = new LinkedList<SQLException>();
        if (x != null) 
            stack.push(x);

        // Limit the chain depth so that poorly written exceptions don't cause an infinite loop.
        for (int depth = 0; depth < 20 && !isAuthError && !stack.isEmpty(); depth++) {
            x = stack.pop();

            isAuthError |= isAuthException(x);

            // Add the chained exceptions to the stack.

            if (x.getNextException() != null)
                stack.push(x.getNextException());
            if (x.getCause() instanceof SQLException && x.getCause() != x.getNextException())
                stack.push((SQLException) x.getCause());
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(this, tc, "isAnAuthorizationException", isAuthError);
        return isAuthError;
    }
370823
public ResultSet getResultSet() throws SQLException {
        SimpleResultSet srs = new SimpleResultSet(this);
        srs.addColumn("THE_GEOM", Types.JAVA_OBJECT, "GEOMETRY", 0, 0);
        srs.addColumn("ID", Types.INTEGER, 10, 0);
        srs.addColumn("ID_COL", Types.INTEGER, 10, 0);
        srs.addColumn("ID_ROW", Types.INTEGER, 10, 0);
        return srs;
    }
430257
public Connection getConnection() throws SQLException {
		
		FinalWrapper<BoneCP> wrapper = this.pool;

        if (wrapper == null) {
                synchronized (this) {
                        if (this.pool == null) {
                        	try{
                        		if (this.getDriverClass() != null){
                        			loadClass(this.getDriverClass());
                        		}
    					
                        		logger.debug(this.toString());
                        		this.pool = new FinalWrapper<BoneCP>(new BoneCP(this));
    				    
                        	} catch (ClassNotFoundException e) {
                        		throw new SQLException(PoolUtil.stringifyException(e));
                        	}
                        }

                        wrapper = this.pool;
                } 
        }

        return wrapper.value.getConnection();
     }
1149846
public boolean next() throws SQLException {
        boolean result = queryResult.next();
        orderValues = result ? getOrderValues() : Collections.<Comparable<?>>emptyList();
        return result;
    }
403120
public static StringBuilder getStackTraceWithState(SQLException sqle) {
        SQLException sqlX = sqle;
        boolean isLinkedThrowable = false;

        StringBuilder trace = new StringBuilder(EOLN); 

        SQLException tempSqlX;
        do {
            StringWriter s = new StringWriter();
            PrintWriter p = new PrintWriter(s);
            sqlX.printStackTrace(p);

            // If it is a linked exception, append link information.
            if (isLinkedThrowable)
                trace.append(
                             "---- Begin backtrace for Nested Throwables").append(
                                                                                  EOLN);

            // Append SQLState, error code and stack trace.
            trace.append("SQL STATE:  " + sqlX.getSQLState()).append(
                                                                     EOLN);
            trace.append("ERROR CODE: " + sqlX.getErrorCode()).append(
                                                                      EOLN);
            trace.append(s.toString());

            // set isLinkedThrowable to true
            isLinkedThrowable = true;
            tempSqlX = sqlX.getNextException();
        } while ((tempSqlX != sqlX) && ((sqlX = tempSqlX) != null)); 

        return trace;

    }
1051049
private boolean query()
		throws SQLException
	{
		statement = this.connection.createStatement();

		String query = "SELECT PrimaryKey, RevisionCounter,"
				+ " RevisionID, ArticleID, Timestamp, FullRevisionID "
				+ "FROM revisions";

		if (primaryKey > 0) {
			query += " WHERE PrimaryKey > " + primaryKey;
		}

		if (MAX_NUMBER_RESULTS > 0) {
			query += " LIMIT " + MAX_NUMBER_RESULTS;
		}

		result = statement.executeQuery(query);
		return result.next();
	}
981667
public void setNextException(SQLException ex) {

        SQLException current = this;
        for(;;) {
            SQLException next=current.next;
            if (next != null) {
                current = next;
                continue;
            }

            if (nextUpdater.compareAndSet(current,null,ex)) {
                return;
            }
            current=current.next;
        }
    }
453556
public int executeUpdate() throws SQLException {
        final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
        SQLExecuteCallback<Integer> executeCallback = SQLExecuteCallbackFactory.getPreparedUpdateSQLExecuteCallback(getDatabaseType(), isExceptionThrown);
        List<Integer> results = executeCallback(executeCallback);
        if (isAccumulate()) {
            return accumulate(results);
        } else {
            return results.get(0);
        }
    }
518595
protected final int doSelect(Connection c) throws SQLException {
		Statement stmt = null;
		ResultSet rs = null;
		try {
			stmt = c.createStatement();
			rs = stmt.executeQuery("select * from foo");
			int count = 0;
			while (rs.next()) {
				count++;
			}
			return count;
		} finally {
			if (rs != null) {
				rs.close();
			}
			if (stmt != null) {
				stmt.close();
			}
		}
	}
890539
public String getExceptionType()
    {
        String exceptionType = null;
        Throwable rootCause = this;
        
        do{
            Throwable temp = ((ServletException)rootCause).getRootCause();
            if(temp != null) {
                rootCause = temp;
            }
            else{
                break;
            }
        }while (rootCause instanceof ServletException);

        // rootCause must be non-null (it started as "this" and was then NEVER set to null by the loop above
        exceptionType = rootCause.getClass().getName();

        return exceptionType;
    }