java - 遍历 resultSet 只给出表中的最后一个对象
问题描述
我一直在尝试遍历我的resultSet
但由于某种原因只选择了我数据库中的最后一个对象。这个想法是我已经从我的数据库中提取了我需要的部分,我现在想将对象添加到我的部分数组列表中。
SectionId 1
例如,我从表中提取了一个名为“Guitar”的部分Sections
,现在想将表sectionmitschueler
中的所有对象添加sectionid = 1
到部分 1 的数组列表中。
resultSet = Persistence.executeQueryStatement(aConnection, "SELECT * "
+ "FROM sectionmitschueler");
while (resultSet.next()) {
for(SectionTO eineSectionTO : eventTO.getSections()) {
if(resultSet.getInt("sectionId") == eineSectionTO.getSectionId())
System.out.println(sectionTO.getSectionId());
sectionTO.getSchueler().add(resultSet.getInt("schuelerId"));
}
}
}
解决方案
推荐阅读
- python - 无法使用 Django 获取外键模型并将其保存到 Sqlite 数据库
- node.js - Node Express-Session 和 React Frontend 不使用 Axios 存储 Cookie
- python - 我是否必须使用 Scikit-learn 从 Pandas 数据框中剪切 y(预测)列?
- python - 多个任务后 Heroku Celery Chrome Headless 上的 Selenium 崩溃
- mysql - MySQL 服务器中的 TLS 证书
- ide - IDE 的问题,当您在编辑器中单击一行时,光标不会转到最后写入的字符
- python - 如何使用python在两个特定字符串之间的网页中查找特定字符串?
- reporting-services - 如何根据 SSRS 报告中的列自定义排序
- c# - 如何在代码中将 3D 模型导入场景中的对象?
- json - jq 求和和乘以得到一个聚合值