tags:

views:

81

answers:

2

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

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.

Here is my code in Java:

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

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

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;

The error occurs on stmt.execute().

Thanks in advance.

By the way, I am working with Oracle 10.2.0.

+1  A: 

Nope, this is wrong. You should not be returning a raw cursor. You should call the stored proc and iterate through the ResultSet.

duffymo
+2  A: 

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.

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.

Dave Costa
Sorry, I mistyped the method name. Is there any Oracle setting or non-code-related problem that may cause this error?
BeginnerAmongBeginners
Turned out that the cursor works fine with JDBC Oracle thin client, but not with ODBC. Not sure about the cause, since I did enable result sets for ODBC.
BeginnerAmongBeginners