java.sql.SQLException.addSuppressed()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中java.sql.SQLException.addSuppressed()方法的一些代码示例,展示了SQLException.addSuppressed()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException.addSuppressed()方法的具体详情如下:
包路径:java.sql.SQLException
类名称:SQLException
方法名:addSuppressed

SQLException.addSuppressed介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

protected static final PreparedStatement prepareStatement(final Connection connection, final String sql, final int resultSetType,
  final int resultSetConcurrency) throws SQLException {
  try {
    return connection.prepareStatement(sql, resultSetType, resultSetConcurrency);
  } catch(final SQLException x) {
    try {
      return connection.prepareStatement(sql);
    } catch(final SQLException x2) {
      x.addSuppressed(x2);
      throw x;
    }
  }
}

代码示例来源: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: jdbi/jdbi

@Override
@SuppressWarnings("PMD.DoNotThrowExceptionInFinally")
public void close() {
  SQLException exception = null;
  try {
    List<Cleanable> cleanables = new ArrayList<>(this.cleanables);
    this.cleanables.clear();
    Collections.reverse(cleanables);
    for (Cleanable cleanable : cleanables) {
      try {
        cleanable.close();
      } catch (SQLException e) {
        if (exception == null) {
          exception = e;
        } else {
          exception.addSuppressed(e);
        }
      }
    }
  } finally {
    if (exception != null) {
      throw new CloseException("Exception thrown while cleaning StatementContext", exception);
    }
  }
}

代码示例来源:origin: prestodb/presto

first.addSuppressed(e);
throw first;

代码示例来源:origin: com.h2database/h2

/**
 * Log an exception and convert it to a SQL exception if required.
 *
 * @param ex the exception
 * @return the SQL exception object
 */
protected SQLException logAndConvert(Throwable ex) {
  SQLException e = null;
  try {
    e = DbException.toSQLException(ex);
    if (trace == null) {
      DbException.traceThrowable(e);
    } else {
      int errorCode = e.getErrorCode();
      if (errorCode >= 23000 && errorCode < 24000) {
        trace.info(e, "exception");
      } else {
        trace.error(e, "exception");
      }
    }
  } catch(Throwable ignore) {
    if (e == null) {
      e = new SQLException("", "HY000", ex);
    }
    e.addSuppressed(ignore);
  }
  return e;
}

代码示例来源:origin: jdbi/jdbi

/**
 * Returns a ResultIterable backed by the given result set supplier, mapper, and context.
 *
 * @param supplier result set supplier
 * @param mapper   row mapper
 * @param ctx      statement context
 * @param <T>      the mapped type
 * @return the result iterable
 */
static <T> ResultIterable<T> of(Supplier<ResultSet> supplier, RowMapper<T> mapper, StatementContext ctx) {
  return () -> {
    try {
      return new ResultSetResultIterator<>(supplier.get(), mapper, ctx);
    } catch (SQLException e) {
      try {
        ctx.close();
      } catch (Exception e1) {
        e.addSuppressed(e1);
      }
      throw new ResultSetException("Unable to iterator result set", e, ctx);
    }
  };
}

代码示例来源:origin: apache/ignite

e.addSuppressed(ex);

代码示例来源:origin: jdbi/jdbi

/**
 * Executes the update, returning the result obtained from the given {@link ResultProducer}.
 *
 * @param <R> the result type
 * @param producer the result producer.
 * @return value returned by the result producer.
 */
public <R> R execute(ResultProducer<R> producer) {
  try {
    return producer.produce(this::internalExecute, getContext());
  } catch (SQLException e) {
    try {
      close();
    } catch (Exception e1) {
      e.addSuppressed(e1);
    }
    throw new UnableToProduceResultException("Could not produce statement result", e, getContext());
  }
}

代码示例来源:origin: jdbi/jdbi

/**
 * Executes the query, returning the result obtained from the given {@link ResultProducer}.
 *
 * @param <R> the type of the result
 * @param producer the result producer.
 * @return value returned by the result producer.
 */
public <R> R execute(ResultProducer<R> producer) {
  try {
    return producer.produce(this::internalExecute, getContext());
  } catch (SQLException e) {
    try {
      close();
    } catch (Exception e1) {
      e.addSuppressed(e1);
    }
    throw new UnableToProduceResultException(e, getContext());
  }
}

代码示例来源:origin: jdbi/jdbi

/**
 * Executes the batch, returning the result obtained from the given {@link ResultProducer}.
 *
 * @param <R> the type of the result
 * @param producer the result producer.
 * @return value returned by the result producer.
 */
public <R> R execute(ResultProducer<R> producer) {
  try {
    return producer.produce(() -> internalBatchExecute().stmt, getContext());
  } catch (SQLException e) {
    try {
      close();
    } catch (Exception e1) {
      e.addSuppressed(e1);
    }
    throw new UnableToProduceResultException("Exception producing batch result", e, getContext());
  }
}

代码示例来源:origin: org.postgresql/postgresql

e.addSuppressed(ex);
e.addSuppressed(ex);

代码示例来源:origin: jdbi/jdbi

stmt.close();
} catch (SQLException e1) {
  e.addSuppressed(e1);

代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.sql

public static SQLException withAllSQLExceptions( SQLException sqlEx )
{
  SQLException next = sqlEx.getNextException();
  while( next != null )
  {
    sqlEx.addSuppressed( next );
    next = next.getNextException();
  }
  return sqlEx;
}

代码示例来源:origin: apache/attic-polygene-java

public static SQLException withAllSQLExceptions( SQLException sqlEx )
{
  SQLException next = sqlEx.getNextException();
  while( next != null )
  {
    sqlEx.addSuppressed( next );
    next = next.getNextException();
  }
  return sqlEx;
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

protected static final PreparedStatement prepareStatement(final Connection connection, final String sql, final int resultSetType,
  final int resultSetConcurrency) throws SQLException {
  try {
    return connection.prepareStatement(sql, resultSetType, resultSetConcurrency);
  } catch(final SQLException x) {
    try {
      return connection.prepareStatement(sql);
    } catch(final SQLException x2) {
      x.addSuppressed(x2);
      throw x;
    }
  }
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-jdbc

public static SQLException close(final Connection connection, final SQLException exception) {
 if (connection == null) {
  return exception;
 }
 try {
  //      if (connection.isClosed()) {
  //        return exception;
  //      }
  connection.close();
  return exception;
 } catch (final SQLException sqlException) {
  if (exception == null) {
   return sqlException;
  }
  exception.addSuppressed(sqlException);
  return exception;
 }
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-jdbc

public static SQLException close(final Statement statement, final SQLException exception) {
 if (statement == null) {
  return exception;
 }
 try {
  //      if (statement.isClosed()) {
  //        return exception;
  //      }
  statement.close();
  return exception;
 } catch (final SQLException sqlException) {
  if (exception == null) {
   return sqlException;
  }
  exception.addSuppressed(sqlException);
  return exception;
 }
}

代码示例来源:origin: org.jdbi/jdbi3

/**
   * 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.
   */
  static SQLException mungeBatchException(SQLException e) {
    for (SQLException next = e.getNextException(); next != null; next = next.getNextException()) {
      e.addSuppressed(next);
    }
    return e;
  }
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-base-jdbc

private RuntimeException handleSqlException(SQLException e)
  {
    try {
      close();
    }
    catch (Exception closeException) {
      e.addSuppressed(closeException);
    }
    return Throwables.propagate(e);
  }
}

代码示例来源:origin: com.blazebit/blaze-persistence-testsuite-base-jpa

@Override
public void clearSchema(Connection c) {
  try (Statement s = c.createStatement()) {
    LOG.log(Level.FINEST, "Dropping schema objects: START");
    s.execute("DROP ALL OBJECTS");
    LOG.log(Level.FINEST, "Dropping schema objects: END");
    LOG.log(Level.FINEST, "Committing: START");
    c.commit();
    LOG.log(Level.FINEST, "Committing: END");
  } catch (SQLException e) {
    try {
      c.rollback();
    } catch (SQLException e1) {
      e.addSuppressed(e1);
    }
    throw new RuntimeException(e);
  }
}

相关文章