CHEBURASHKA
CHEBURASHKA

Reputation: 1713

How to get ResultSet from executeBatch?

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 ?

Upvotes: 8

Views: 8997

Answers (3)

sisi_the_se
sisi_the_se

Reputation: 1

According to the Java 7 API, the 'executeBatch" function doesn't return an object of ResultSet, but an array of integers. You can process the values based on the API to see which commands in the batch were successful.

Upvotes: 0

user9794575
user9794575

Reputation: 11

I can think of 2 options from the top of my head.

1) As the other guy said... "Plain multiple execute() should be used" this way you can get the result set.

2) you can query after you execute your batch and get its info from the db.

Upvotes: 1

Dennis C
Dennis C

Reputation: 24747

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.

Upvotes: 7

Related Questions