简体   繁体   中英

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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM