我需要从执行的批处理中获取结果集:
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();
我执行批处理如何从select查询中获取结果集?
答案 0 :(得分:5)
简而言之,你不应该。应该使用Plain multiple execute()。
根据javadoc of executeBatch()
,它不应该支持getResultSet()/ getMoreResults()API。
此外,在JDBC™ 4.0 Specification#14.1.2
中只有返回简单更新计数的DDL和DML命令可能是 作为批次的一部分执行。方法executeBatch抛出一个 BatchUpdateException如果批处理中的任何命令失败 正确执行或命令尝试返回结果集。
但是有些JDBC驱动程序可能会支持,请自担风险。
答案 1 :(得分:0)
我可以从头脑中想到两个选项。
1)正如另一个人说的...... "应该使用Plain multiple execute()" 这样你就可以得到结果集。
2)您可以在执行批处理后查询并从数据库中获取其信息。