java - 批处理中的 PreparedStatement clearParameters()
问题描述
我有以下代码片段 -
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 数据库。
谢谢!
解决方案
推荐阅读
- android - Kotlin 代码在编译时会“缩小”吗?
- angular - 在获得角度响应后,如何在选择标签上将其余 api 调用中的值设置为 ngModel
- gtk - 如何在 GTK4 中使窗口居中?
- hbase - 具有设置字段的记录的 Bigtable 行键设计
- r - GLMM - R 的 Huber-White 稳健标准误差
- winapi - SRW Lock 可以用作二进制信号量吗?
- python - 如何使用 tensorflow 注意力层?
- c# - 如何在一段时间内和外部从列表中获取元素
- python - 获取真实值的熊猫系列标签,而不将系列存储在临时变量中
- python - 在计算运行中出现的次数时创建不重复的新列表