我需要多次调用存储过程并使用executeBatch()
为了这。每次调用都应返回包含结果的表,但我无法访问此结果。接下来的代码工作正常:
callableStatement.setString(1, "foo");
callableStatement.setString(2, "bar");
callableStatement.execute();
resultSet = callableStatement.getResultSet();
但接下来的代码无法按预期工作:
for (String str : strings) {
callableStatement.setString(1, str);
callableStatement.setString(2, "bar");
callableStatement.addBatch();
}
callableStatement.executeBatch();
resultSet = callableStatement.getResultSet(); // returns null
我已经尝试打电话了callableStatement.getUpdateCount()
and callableStatement.getMoreResults()
在提取 ResultSet 之前,但未成功。
这并不是真正的正确用法#executeBatch
。批处理方法用于进行数据操作而不是获取结果数据。也就是说,您可以进行批量插入/更新/删除,但不能进行读取。的结果#executeBatch
是 update-count,表示每批操作进行了多少次更改
目的是您可以通过减少类似数据操作操作的网络开销和数据库往返来提高性能。
您通常不会批量执行查询,因为不同的查询会导致不同的形状ResultSet
(除非它们都用于具有相同列但不同查询的同一个表[但为什么不直接修改您的查询])。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)