CURSOR 和 REF CURSOR 作为 JDBC 数据类型 [英] CURSOR and REF CURSOR as a JDBC data type

查看:33
本文介绍了CURSOR 和 REF CURSOR 作为 JDBC 数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多 RDBMS 支持某种类型的CURSOR"类型.这些类型在从存储过程返回时最有用.Oracle 中的示例:

Many RDBMS support "CURSOR" types of some sort. Those types are mostly useful when returned from stored procedures. An example in Oracle:

TYPE t_cursor_type IS REF CURSOR;
CREATE PROCEDURE p (c OUT t_cursor_type);

使用 JDBC 调用此过程时,应使用 OracleTypes.CURSOR = -10JDBC"类型.这种类型不是任何标准的一部分,也不会成为 Java 7 中 JDBC 4.1 的一部分.

When calling this procedure using JDBC, the OracleTypes.CURSOR = -10 "JDBC" type should be used. This type is not part of any standard and it is not going to be part of JDBC 4.1 in Java 7.

有谁知道 JSR 人员是否会考虑在未来某个时候将这种类型添加到标准中?或者其他 RDBMS 是否具有类似的特定于供应商的类型"?

Does anyone know whether the JSR guys will consider adding this type to the standard some time in the future? Or if other RDBMS have a similar "vendor-specific type"?

推荐答案

在 Java 8/JDBC 4.2 中添加了对 REF CURSORS 的支持.使用类型 Types.REF_CURSOR 用于游标返回类型.它们可以通过 ResultSet 接口进行迭代.示例:

Support for REF CURSORS was added in Java 8/JDBC 4.2. Use the type Types.REF_CURSOR for cursor return types. They can be iterated through the ResultSet interface. Example:

CallableStatement cstmt = conn.prepareCall("{callmySproc(?)}");
cstmt.registerOutParameter(1, Types.REF_CURSOR);
cstmt.executeQuery();
ResultSet cursor = cstmt.getObject(1, ResultSet.class);
while(cursor.next()) {
    System.out.println("Name = " + cursor.getString(1));
}

这篇关于CURSOR 和 REF CURSOR 作为 JDBC 数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆