gpt4 book ai didi

java - H2:executeBatch 不起作用

转载 作者:行者123 更新时间:2023-11-30 08:11:55 25 4
gpt4 key购买 nike

我有以下代码

String query = "INSERT INTO student (age,name) VALUES (?,?)";
conn.setAutoCommit(true);
ps = conn.prepareStatement(query);
for (Student student:list) {
ps.setInt(1, student.getAge());
ps.setString(2, student.getName());
}
int[]temp=ps.executeBatch();
System.out.println("TEMP:"+temp.length);//returns 0

执行的代码。没有错误没有异常(exception)。但是学生表是空的。我在嵌入式模式下使用 h2 1.3.176。怎么了?

最佳答案

您忘记添加批量参数集:

String query = "INSERT INTO student (age,name) VALUES (?,?)";
conn.setAutoCommit(true);
ps = conn.prepareStatement(query);
for (Student student:list) {
ps.setInt(1, student.getAge());
ps.setString(2, student.getName());
ps.addBatch(); // <--
}
int[]temp=ps.executeBatch();
System.out.println("TEMP:"+temp.length);

关于java - H2:executeBatch 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30760373/

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