我在JDBC中遇到批处理问题,我向批处理中添加了一条准备好的语句,但是当我执行批处理时,仅插入了几条记录,我进行了搜索,但并未弄清楚,这是代码:
我正在准备另一个声明的结果集,这有问题吗?谢谢!
//autocommitFALSE (...)
while(rs.next()){
int idrobot = rs.getInt("idRobot");
if (idrobot != idrn) {
String fullstatenew2 = "INSERT INTO `fullstate`(`idR`, `idC`, `s1`, `s2`, `s3`, `s4`, `s5`, `s6`, `s7`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
java.sql.PreparedStatement preparedStmt9 = conn.prepareStatement(fullstatenew2);
preparedStmt9.setInt(1, robot);
preparedStmt9.setString(2, cluster);
preparedStmt9.setInt(3, s1);
preparedStmt9.setInt(4, s2);
preparedStmt9.setInt(5, s3);
preparedStmt9.setInt(6, s4);
preparedStmt9.setInt(7, s5);
preparedStmt9.setInt(8, s6);
preparedStmt9.setInt(9, s7);
preparedStmt9.addBatch();
if(i>10000) //it's really not like this, but this is the sense {
preparedStmt9.executeBatch();
System.out.println("insert");
}
conn.commit();
最佳答案
添加批处理应该在循环中,执行批处理应该在循环之后。