简体   繁体   中英

PLS-00306: wrong number or types of arguments in call to GET_NEW_EVENTS in Java

I'm getting the below error while calling a stored procedure from Java:

"java.sql.SQLException: [Oracle][ODBC][Ora]ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'GET_NEW_EVENTS' ORA-06550: line 1, column 7: PL/SQL: Statement ignored"

The stored procedure is as below:

    create or replace package body event_subscription as
    procedure get_new_events( p_events in out SYS_REFCURSOR ) as
    begin
        open p_events for
            select log_id from event_alert_log;         
    end get_new_events;
end event_subscription;

And the Java code to cal the stored procedure is as below:

    sqlString = "BEGIN event_subscription.get_new_events(?); END;";
CallableStatement  cs = connection.prepareCall(sqlString);
cs.registerOutParameter(1,OracleTypes.CURSOR);
cs.execute(); // This line is failing and throwing the SQLException
ResultSet rs = (ResultSet) cs.getObject(1);

The Oracle Version is: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product The Java version is: 1.6.

Can somebody help me in this issue. I have been trying all possible solutions to this problem.

Odd. I can't reproduce this. I'm using Oracle XE 11.2.0.2.0 on Windows 7 x64, with version 11.2.0.2.0 of ojdbc6.jar .

I don't have your tables, so instead I queried a data dictionary view. I created the following package

create or replace package event_subscription as
   procedure get_new_events( p_events out SYS_REFCURSOR );
end;

create or replace package body event_subscription as
    procedure get_new_events( p_events out SYS_REFCURSOR )
    as
    begin
        open p_events for
            select object_name, object_type from all_objects where rownum <= 10;
    end get_new_events;
end event_subscription;

and compiled the following Java class:

import java.sql.*;

public class So12751878 {
    public static void main(String[] args) throws Exception {
        new oracle.jdbc.OracleDriver();
        Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "user", "password");
        String sqlString = "BEGIN event_subscription.get_new_events(?); END;";
        CallableStatement cs = connection.prepareCall(sqlString);
        cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
        cs.execute();
        ResultSet rs = (ResultSet) cs.getObject(1);
        while (rs.next()) {
            System.out.println("Got '" + rs.getString(1) + "' and '" + rs.getString(2) + "'.");
        }
    }
}

This ran successfully. It also ran successfully if I changed the stored procedure's parameter from OUT to IN OUT .

EDIT : you've now clarified in your comment that you're using the JDBC-ODBC bridge driver to connect to Oracle. However, you're registering the type of the parameter as oracle.jdbc.OracleTypes.CURSOR . This type is specific to the Oracle JDBC driver, and therefore not something I would expect the JDBC-ODBC bridge driver to understand, given that it has to support multiple databases.

Moral of the story: don't use the JDBC-ODBC bridge driver to connect to Oracle if using OracleTypes.* constants. Better still, don't use the JDBC-ODBC bridge driver to connect to Oracle.

That's because you have an IN OUT parameter, so you must set the IN, for example:

cs.setInt(1, -2);

and then the outparameter you already have. Both.

cs.registerOutParameter(1,OracleTypes.CURSOR); 

There's the problem you get having a cursor IN... that won't work as IN parameter. Are you really going to send a refcursor as parameter?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM