2014-02-06 60 views
3

我需要的結果從執行批量設定:如何從executeBatch獲取ResultSet?

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(); 

那些我執行批處理我怎樣才能得到結果從選擇查詢設置?

+0

可能的重複http://stackoverflow.com/questions/21118698/retrieve-resultset-using-callablestatement-after-executebatch –

回答

4

總之,你不應該。應該使用簡單的多個execute()。

根據javadoc of executeBatch(),它不應該支持getResultSet()/ getMoreResults()API。

另外,在JDBC™ 4.0 Specification#14.1.2

只有DDL和DML命令返回一個簡單的更新計數可以作爲間歇的一部分來 執行。如果批處理中的任何命令無法正常執行,或者命令嘗試返回結果集,則executeBatch方法會拋出 BatchUpdateException。

但是有些JDBC驅動程序可能會支持,請自行承擔風險。

+0

謝謝。 +1所以我應該怎麼做才能從包含多個語句的查詢中獲取ResultSet? – CHEBURASHKA