在没有Oracle依赖的Java中使用Oracle引用游标

根据谷歌和其他一些消息来源(例如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); 

无论如何都没有在Oracle上引入编译时依赖性。 是否有OracleTypes.CURSOR的通用替代方案?

常量OracleTypes.CURSOR为-10。 相当难看的解决方案,但你可以在那里写-10或创建自己的常量,其值为-10。

你试过java.sql.Types.OTHER吗? 它可能会奏效。 API表示,它适用于特定于数据库的类型。