public static SQLClientInfoException toSQLClientInfoException(Throwable t) {
   if (t instanceof SQLClientInfoException) return (SQLClientInfoException) t;
   else if (t.getCause() instanceof SQLClientInfoException)
     return (SQLClientInfoException) t.getCause();
   else if (t instanceof SQLException) {
     SQLException sqle = (SQLException) t;
     return new SQLClientInfoException(
         sqle.getMessage(), sqle.getSQLState(), sqle.getErrorCode(), null, t);
   } else return new SQLClientInfoException(t.getMessage(), null, t);
 }
  //
  // Examine a single method to see if it raises SQLFeatureNotSupportedException.
  //
  private void vetMethod(
      Object candidate,
      Class iface,
      Method method,
      HashSet<String> unsupportedList,
      HashSet<String> notUnderstoodList)
      throws Exception {
    try {
      method.invoke(candidate, getNullArguments(method.getParameterTypes()));

      // it's ok for the method to succeed
    } catch (Throwable e) {
      if (!(e instanceof InvocationTargetException)) {
        recordUnexpectedError(candidate, iface, method, notUnderstoodList, e);
      } else {
        Throwable cause = e.getCause();

        if (cause instanceof SQLFeatureNotSupportedException) {
          boolean isExcludable = isExcludable(method);

          if (!isExcludable) {
            StackTraceElement[] stack = cause.getStackTrace();
            int i = 0;
            while (i < stack.length && !stack[i].getMethodName().equals("notImplemented")) {
              ++i;
            }
            while (i < stack.length && stack[i].getMethodName().equals("notImplemented")) {
              ++i;
            }
            if (i == stack.length) {
              // cause.printStackTrace();
            }

            unsupportedList.add(
                candidate.getClass().getName()
                    + ": "
                    + method
                    + "@"
                    + (i == stack.length ? "no source" : cause.getStackTrace()[i]));
          } else {

          }
        } else if (cause instanceof SQLException) {
          // swallow other SQLExceptions, caused by bogus args
        } else if (cause instanceof NullPointerException) {
          // swallow other NPEs, caused by bogus args
        } else if (cause instanceof ArrayIndexOutOfBoundsException) {
          // swallow these, caused by bogus args
        } else {
          recordUnexpectedError(candidate, iface, method, notUnderstoodList, cause);
        }
      }
    }
  }
Esempio n. 3
0
  /**
   * The SQLException instance contains the following information that can help determine the cause
   * of the error:
   *
   * <p>A description of the error. Retrieve the String object that contains this description by
   * calling the method SQLException.getMessage.
   *
   * <p>A SQLState code. These codes and their respective meanings have been standardized by
   * ISO/ANSI and Open Group (X/Open), although some codes have been reserved for database vendors
   * to define for themselves. This String object consists of five alphanumeric characters. Retrieve
   * this code by calling the method SQLException.getSQLState.
   *
   * <p>An error code. This is an integer value identifying the error that caused the SQLException
   * instance to be thrown. Its value and meaning are implementation-specific and might be the
   * actual error code returned by the underlying data source. Retrieve the error by calling the
   * method SQLException.getErrorCode.
   *
   * <p>A cause. A SQLException instance might have a causal relationship, which consists of one or
   * more Throwable objects that caused the SQLException instance to be thrown. To navigate this
   * chain of causes, recursively call the method SQLException.getCause until a null value is
   * returned.
   *
   * <p>A reference to any chained exceptions. If more than one error occurs, the exceptions are
   * referenced through this chain. Retrieve these exceptions by calling the method
   * SQLException.getNextException on the exception that was thrown.
   *
   * <p>Retrieving Exceptions
   *
   * <p>The following method, JDBCTutorialUtilities.printSQLException outputs the SQLState, error
   * code, error description, and cause (if there is one) contained in the SQLException as well as
   * any other exception chained to it:
   *
   * @param ex The SQLException thrown by the function in question.
   */
  public static void printSQLException(SQLException ex) {

    for (Throwable e : ex) {
      if (e instanceof SQLException && !ignoreSQLException(((SQLException) e).getSQLState())) {

        e.printStackTrace(System.err);
        Logger.logMsg(1, "SQLState: " + ((SQLException) e).getSQLState());

        Logger.logMsg(1, "Error Code: " + ((SQLException) e).getErrorCode());

        Logger.logMsg(1, "Message: " + e.getMessage());

        Throwable t = ex.getCause();
        while (t != null) {
          Logger.logMsg(1, "Cause: " + t);
          t = t.getCause();
        }
      }
    }
  }
Esempio n. 4
0
  /**
   * The following methods were obtained from
   * http://docs.oracle.com/javase/tutorial/jdbc/basics/sqlexception.html
   *
   * <p>They privide a useful way of handling SQL Exceptions They will produce clear & readable
   * error meesages to aid debugging
   */
  private void printSQLException(SQLException ex) {

    for (Throwable e : ex) {
      if (e instanceof SQLException) {
        if (ignoreSQLException(((SQLException) e).getSQLState()) == false) {

          e.printStackTrace(System.err);
          System.err.println("SQLState: " + ((SQLException) e).getSQLState());

          System.err.println("Error Code: " + ((SQLException) e).getErrorCode());

          System.err.println("Message: " + e.getMessage());

          Throwable t = ex.getCause();
          while (t != null) {
            System.out.println("Cause: " + t);
            t = t.getCause();
          }
        }
      }
    }
  }