如何从executeBatch获取ResultSet?
我需要从执行的批处理中获取结果集:
String [] queries = {"create volatile table testTable as (select * from orders) with data;", "select top 10 * from testTable;" , "drop table testTable" }; for (String query : queries) { statement.addBatch(query); } statement.executeBatch();
我执行批处理如何从选择查询中获取结果集?
简而言之,你不应该。 应该使用Plain multiple execute()。
正如根据executeBatch()
的javadoc ,它不应该支持getResultSet()/ getMoreResults()API。
此外,在JDBC™4.0规范 #14.1.2中
只有返回简单更新计数的DDL和DML命令可以作为批处理的一部分执行。 如果批处理中的任何命令无法正确执行或命令尝试返回结果集,则executeBatch方法将抛出BatchUpdateException。
但是一些JDBC驱动程序可能会支持,请自担风险。
我可以从脑海中想到两个选项。
1)正如另一个人说的那样……“应该使用Plain multiple execute()”这样你可以得到结果集。
2)您可以在执行批处理后查询并从数据库中获取其信息。