在不依赖Oracle的Java中使用Oracle ref游标 [英] Using Oracle ref cursor in Java without Oracle dependency

查看:77
本文介绍了在不依赖Oracle的Java中使用Oracle ref游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Google和其他一些来源(例如, http://www.enterprisedt. com/publications/oracle/result_set.html ),如果我想调用一个返回引用游标的存储函数,则需要编写如下代码才能访问ResultSet:

According to google and some other sources (e.g., http://www.enterprisedt.com/publications/oracle/result_set.html), if I want to call a stored-function that returns a ref cursor, I need to write something like this in order to access the ResultSet:

String query = "begin ? := sp_get_stocks(?); end;";
CallableStatement stmt = conn.prepareCall(query);
// register the type of the out param - an Oracle specific type
stmt.registerOutParameter(1, OracleTypes.CURSOR);
// set the in param
stmt.setFloat(2, price);
// execute and retrieve the result set
stmt.execute();
ResultSet rs = (ResultSet)stmt.getObject(1);

在没有引入对Oracle的编译时依赖性的情况下,仍然可以做到这一点.是否有OracleTypes.CURSOR的通用替代方法?

Is there anyway to do it without introducing the compile-time dependency on Oracle. Is there a generic alternative to OracleTypes.CURSOR?

推荐答案

常量OracleTypes.CURSOR为-10.很丑陋的解决方案,但是您可以在那里写-10或创建自己的值为-10的常量.

Constant OracleTypes.CURSOR is -10. Quite ugly solution but you can just write -10 there or create your own constant which value is -10.

这篇关于在不依赖Oracle的Java中使用Oracle ref游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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