我有以下代码段-
String sql = "insert into A (c1, c2, c3) values (?, ?, ?)";
Connection connection = new getConnection();
PreparedStatement ps = connection.prepareStatement(sql);
for (Employee employee: employees) {
ps.setString(1, employee.getName());
ps.setString(2, employee.getCity());
if (StringUtils.isNotBlank(employee.getPhone()))
{
ps.setString(3, employee.getPhone());
}
else
{
// add a warning log - I do not want to throw an exception
ps.clearParameters();
continue;
}
ps.addBatch();
}
ps.executeBatch();
上述工作是否不会将特定的员工记录添加到批次中?我试图重现此信息,但由于无法访问某些系统,因此不确定结果。我通读了clearParameters()的描述,它确实指出了在批处理方案中会发生什么。它是否仅删除该特定记录的参数?如果依赖于底层驱动程序,我将使用H2数据库。
谢谢!