正 文

解析J2EE1.4新特性(3)-JDBC3.0的新特性


www.7dspace.com  更新日期:2006-2-11 12:09:43  七度空间


3、返回多重结果

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 对象将不会被关闭。

下面展示的是一个处理多重打开结果的示例。

……

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

// …

 }

}

……

5页,页码:[1] [2] [3] [4] [5] 

上一篇:解析J2EE1.4新特性(4) - EJB2.1的新特性
下一篇:解析J2EE1.4新特性(2)-Servlet 2.4的新特性
标题:解析J2EE1.4新特性(3)-JDBC3.0的新特性 作者:务实 来源:开发者在线
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐