在不依赖 Oracle 的情况下在 Java 中使用 Oracle 引用游标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/445455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:41:44  来源:igfitidea点击:

Using Oracle ref cursor in Java without Oracle dependency

javaoracle

提问by Yoni

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:

根据谷歌和其他一些来源(例如,http: //www.enterprisedt.com/publications/oracle/result_set.html),如果我想调用一个返回引用游标的存储函数,我需要写一些类似的东西这是为了访问 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);

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

有没有办法在不引入对 Oracle 的编译时依赖的情况下做到这一点。是否有 OracleTypes.CURSOR 的通用替代方案?

采纳答案by martsraits

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

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

回答by martsraits

Have you tried java.sql.Types.OTHER? It might work. API says, it's for database specific types.

你试过java.sql.Types.OTHER吗?它可能会起作用。API 说,它是针对数据库特定类型的。