How to get ResultSet from executeBatch?

java, sql

Solution

In short, you should not. Plain multiple execute() should be used.

As as according to the javadoc of `executeBatch()`, it should not support getResultSet()/getMoreResults() API.

Also, in JDBC™ 4.0 Specification #14.1.2

Only DDL and DML commands that return a simple update count may be executed as part of a batch. The method executeBatch throws a BatchUpdateException if any of the commands in the batch fail to execute properly or if a command attempts to return a result set.

But some JDBC drivers might do support, try at your own risk.

Problem

I need to get the result set from an executed batch : ``` 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(); ``` Ones i execute batch how can i get the result set from the select query ?

Original source

Related problems