首页 > 解决方案 > 关闭结果集:某些记录出错。9/10 次它可以工作,但仅在记录批量处理时对少数记录失败

问题描述

在少数情况下,我会遇到错误。在处理 20 条记录时,大约 1-2 条记录低于错误。有时它也适用于 200 条记录。有时它会因为结果集关闭错误的少数记录而失败。

stackTrace com.xyz.abc.exceptions.customException:关闭结果集:com.xyz.setlib.util.SetUtils.getTagsIds(SetUtils.java:54)

下面是我收到错误的代码片段。有人可以指导我了解为什么会发生这种情况以及如何解决。提前致谢。

注意:下面的代码是用静态方法编写的

public static List<Long> getSetIds(...params) {
    String sql = "select asset_tag_id from mytable  where set_id = ?";
    List<Long> resultAsLong = new ArrayList<Long>();
    Connection connection = null;
    // get the result
    try {
        connection = ConnectionProvider.getConnection();
        PreparedStatement stmt = connection.prepareStatement(sql);
        stmt.setLong(1, setId);
        try (ResultSet rs = stmt.executeQuery()) {

            while (rs.next()) {
                resultAsLong.add(rs.getLong(1));
            }
        } catch (Exception e) {
            log.error("Error while getting data from fetched records. Error ",e);
            throw new customException(e.getMessage());
        }
    } catch (Exception e) {
        log.error("Error while fetching data from DB. Error ", e);
        throw new customException(e.getMessage());
    }

    return resultAsLong;
}

标签: javaoraclejdbcresultset

解决方案


推荐阅读