使用JDBC检索Oracle Cursor [英] Retrieving Oracle Cursor with JDBC

查看:104
本文介绍了使用JDBC检索Oracle Cursor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使简单的Oracle游标检索过程与JDBC一起使用时,我遇到了一些挫败感.

I have been experiencing some frustrations trying to make a simple Oracle cursor retrieval procedure work with JDBC.

我不断收到"[Oracle] [ODBC] [Ora] ORA-06553:PLS-306:对"GETNAME"的调用中的参数数目或类型错误"的错误,但我无法弄清楚自己是什么做错了.

I keep on getting an error of "[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'GETNAME'", but I cannot figure out what I am doing wrong.

这是我的Java代码:

Here is my code in Java:

CallableStatement stmt = connection.prepareCall("call getName(?)");
stmt.registerOutParameter(1, OracleTypes.CURSOR);
stmt.execute();

stmt.close();
con.close();

这是我在Oracle中的过程:

Here is my procedure in Oracle:

CREATE OR REPLACE PROCEDURE getName(cur out SYS_REFCURSOR)
IS
BEGIN
    OPEN cur FOR
        SELECT name FROM customer;
END;

该错误发生在stmt.execute()上.

谢谢.

顺便说一下,我正在使用Oracle 10.2.0.

By the way, I am working with Oracle 10.2.0.

推荐答案

我尝试了基本上相同的操作,并且对我有用.唯一的区别是我使用的Oracle JDBC库没有方法registerOutputParameter;我改用registerOutParameter.也许您正在调用一种通用的JDBC方法,而不是支持Oracle类型的特定于Oracle的方法.

I tried essentially the same thing and it worked for me. The only difference was that the Oracle JDBC library I am using does not have a method registerOutputParameter; I used registerOutParameter instead. Perhaps you are calling a generic JDBC method instead of the Oracle-specific one that support Oracle types.

我能想到的唯一的另一种解释是,您的Java代码正在连接到错误的架构,并访问了另一个getName对象.

The only other explanation I can think of is that your Java code is connecting to the wrong schema, and accessing a different getName object.

这篇关于使用JDBC检索Oracle Cursor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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