H2:executeBatch 不起作用
H2: executeBatch doesn't work
我有以下代码
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
执行的代码。没有错误没有例外。但是 table 个学生是空的。我在嵌入式模式下使用 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);
我有以下代码
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
执行的代码。没有错误没有例外。但是 table 个学生是空的。我在嵌入式模式下使用 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);