gpt4 book ai didi

java preparedStatement.executeUpdate() 只插入最后一行

转载 作者:行者123 更新时间:2023-12-01 22:25:42 24 4
gpt4 key购买 nike

这是我的代码:

String insertQuery = "INSERT INTO Links(PageId, LinkId) values(?, ?)";
PreparedStatement preparedStatement = con.prepareStatement(insertQuery);
Vector<String> links = page.getLinks();
for (String string : links) {
Concept c = dbpedia.findConceptbyTitle(string);
if (c != null) {
preparedStatement.setInt(1, Integer.parseInt(page.getID()));
preparedStatement.setInt(2, c.id);
}
}
preparedStatement.executeUpdate();

奇怪的是,当我在executeUpdate之后设置断点时,只有最后一行插入到SQL表中!

最佳答案

添加preparedStatement.addBatch();在你离开循环之前。

并替换preparedStatement.executeUpdate();与preparedStatement.executeBatch();。

关于java preparedStatement.executeUpdate() 只插入最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28815727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com