Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ResultSet from executeBatch?

Tags:

java

sql

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 ?

like image 459
CHEBURASHKA Avatar asked Feb 06 '14 01:02

CHEBURASHKA


People also ask

How do I get my ResultSet first record?

You can move the cursor of the ResultSet object to the first row from the current position, using the first() method of the ResultSet interface. This method returns a boolean value specifying whether the cursor has been moved to the first row successfully.

Which method is used to retrieve the ResultSet created?

The ResultSet interface declares getter methods (for example, getBoolean and getLong ) for retrieving column values from the current row. You can retrieve values using either the index number of the column or the alias or name of the column.

How do I get a row from ResultSet?

The getRow() method of the ResultSet interface retrieves the current row number/position of the ResultSet pointer. This method returns an integer value representing the current row number to which the ResultSet pointer points to.


1 Answers

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.

like image 51
Dennis C Avatar answered Oct 15 '22 18:10

Dennis C