private String formatString(
        MLevel l, String srcClass, String srcMeth, String msg, Object[] params, Throwable t) {
      boolean add_parens = (srcMeth != null && !srcMeth.endsWith(")"));

      StringBuffer sb = new StringBuffer(256);
      sb.append(l.getLineHeader());
      sb.append(' ');
      if (srcClass != null && srcMeth != null) {
        sb.append('[');
        sb.append(srcClass);
        sb.append('.');
        sb.append(srcMeth);
        if (add_parens) sb.append("()");
        sb.append(']');
      } else if (srcClass != null) {
        sb.append('[');
        sb.append(srcClass);
        sb.append(']');
      } else if (srcMeth != null) {
        sb.append('[');
        sb.append(srcMeth);
        if (add_parens) sb.append("()");
        sb.append(']');
      }
      if (msg == null) {
        if (params != null) {
          sb.append("params: ");
          for (int i = 0, len = params.length; i < len; ++i) {
            if (i != 0) sb.append(", ");
            sb.append(params[i]);
          }
        }
      } else {
        if (params == null) sb.append(msg);
        else {
          MessageFormat mfmt = new MessageFormat(msg);
          sb.append(mfmt.format(params));
        }
      }

      if (t != null) {
        sb.append(SEP);
        sb.append(ThrowableUtils.extractStackTrace(t));
      }

      return sb.toString();
    }
예제 #2
0
  public static SQLException toSQLException(String msg, String sqlState, Throwable t) {
    if (t instanceof SQLException) {
      if (Debug.DEBUG && Debug.TRACE == Debug.TRACE_MAX && logger.isLoggable(MLevel.FINER)) {
        SQLException s = (SQLException) t;
        StringBuffer tmp = new StringBuffer(255);
        tmp.append("Attempted to convert SQLException to SQLException. Leaving it alone.");
        tmp.append(" [SQLState: ");
        tmp.append(s.getSQLState());
        tmp.append("; errorCode: ");
        tmp.append(s.getErrorCode());
        tmp.append(']');
        if (msg != null) tmp.append(" Ignoring suggested message: '" + msg + "'.");
        logger.log(MLevel.FINER, tmp.toString(), t);

        SQLException s2 = s;
        while ((s2 = s2.getNextException()) != null)
          logger.log(MLevel.FINER, "Nested SQLException or SQLWarning: ", s2);
      }
      return (SQLException) t;
    } else {
      if (Debug.DEBUG) {
        // t.printStackTrace();
        if (logger.isLoggable(MLevel.FINE))
          logger.log(MLevel.FINE, "Converting Throwable to SQLException...", t);
      }

      if (msg == null)
        msg = "An SQLException was provoked by the following failure: " + t.toString();
      if (VersionUtils.isAtLeastJavaVersion14()) {
        SQLException out = new SQLException(msg);
        out.initCause(t);
        return out;
      } else
        return new SQLException(
            msg
                + System.getProperty("line.separator")
                + "[Cause: "
                + ThrowableUtils.extractStackTrace(t)
                + ']',
            sqlState);
    }
  }
 public String sampleLastConnectionTestFailureStackTrace(String username, String password)
     throws SQLException {
   Throwable t = getLastConnectionTestFailure(username, password);
   return t == null ? null : ThrowableUtils.extractStackTrace(t);
 }
 public String sampleLastConnectionTestFailureStackTraceDefaultUser() throws SQLException {
   Throwable t = getLastConnectionTestFailureDefaultUser();
   return t == null ? null : ThrowableUtils.extractStackTrace(t);
 }