java - 关闭结果集:某些记录出错。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;
}
解决方案
推荐阅读
- python-3.x - 使用 vnc 到 Raspberry 时没有 kivy GUI
- php - 访问PHPMailer的RecipientsQueue
- jenkins - 输入私钥时缺少 Jenkins 选项;“来自詹金斯大师的文件”和“来自詹金斯大师〜/ .ssh”
- gps - 如何从 csv 格式的虚假 AVL 提要创建 GTFS_RT 提要
- javascript - 使用反应生命周期解决 jquery .bind() 匿名函数中不可访问的变量
- sql-server - SQL Server Profiler 中的数据与扩展事件不一致
- c# - 反序列化列表
- r - 合并R中的几个数据框列
- javascript - Jquery + Ajax,Params 有数据,但响应说没有数据
- reactjs - 对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。起源