-----关于,返回多丛结果集的讨论。。。。

02-12-10 swpcute

返回多重结果
JDBC 2 规范的一个局限是,在任意时刻,返回多重结果的语句只能打开一个 ResultSet。作为 JDBC 3.0 规范中改变的一个部分,规范将允许 Statement 接口支持多重打开的 ResultSets。然而,重要的是 execute() 方法仍然会关闭任何以前 execute() 调用中打开的 ResultSet。所以,要支持多重打开的结果,Statement 接口就要加上一个重载的 getMoreResults() 方法。新式的方法会做一个整数标记,在 getResultSet() 方法被调用时指定前一次打开的 ResultSet 的行为。接口将按如下所示定义标记:

CLOSE_ALL_RESULTS 当调用 getMoreResults() 时,所有以前打开的 ResultSet 对象都将被关闭。 
CLOSE_CURRENT_RESULT 当调用 getMoreResults() 时,当前的 ResultSet 对象将被关闭。 
KEEP_CURRENT_RESULT 当调用 getMoreResults() 时,当前的 ResultSet 对象将不会被关闭。 

清单 2 展示的是一个处理多重打开结果的示例。

清单 2. 如何处理多重打开结果

--------------------------------------------------------------
String procCall;

// Set the value of procCall to call a stored procedure.

// ...



CallableStatement cstmt = connection.prepareCall(procCall);

int retval = cstmt.execute();

if (retval == false) {

    // The statement returned an update count, so handle it.

    // ...

} else { // ResultSet

    ResultSet rs1 = cstmt.getResultSet();

    // ...



    retval = cstmt.getMoreResults(Statement.KEEP_CURRENT_RESULT);

    if (retval == true) {

        ResultSet rs2 = cstmt.getResultSet();
        


        // Both ResultSets are open and ready for use.

        rs2.next();

        rs1.next();

        // ...

    }

}

-------------------------------------------------------------

再这个程序当中,不管怎么创建结果集。只对一个表进行操作。
不是变的没有意义了。。。


 
<p class="indent">

Jevang
2002-12-10 11:17
To my knowledge, multiple resultsets are only supported by sqlserver and sybase, even now it's part of standard JDBC, you won't see wide support from DB vendors. My point is: who care this feature, it make your app not portable.

Just my 2 cents