[英]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调用存储过程时出现以下错误:
"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" “ java.sql.SQLException:[Oracle] [ODBC] [Ora] ORA-06550:第1行,第7列:PLS-00306:对“ GET_NEW_EVENTS”的调用中参数的数量或类型错误ORA-06550:第1行,第7:PL / SQL:语句被忽略”
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: 用来计算存储过程的Java代码如下:
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. Oracle版本为:Oracle数据库10g快捷版10.2.0.1.0版-产品Java版本为: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
. 我正在Windows 7 x64上使用Oracle XE 11.2.0.2.0,以及ojdbc6.jar的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: 并编译了以下Java类:
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
. 如果我将存储过程的参数从OUT
更改为IN OUT
它也成功运行。
EDIT : you've now clarified in your comment that you're using the JDBC-ODBC bridge driver to connect to Oracle. 编辑 :您现在已经在注释中阐明您正在使用JDBC-ODBC桥驱动程序来连接到Oracle。 However, you're registering the type of the parameter as oracle.jdbc.OracleTypes.CURSOR
. 但是,您正在将参数的类型注册为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. 这种类型特定于Oracle JDBC驱动程序,因此,鉴于它必须支持多个数据库,因此我不希望JDBC-ODBC桥驱动程序能够理解。
Moral of the story: don't use the JDBC-ODBC bridge driver to connect to Oracle if using OracleTypes.*
constants. 故事的寓意:如果使用OracleTypes.*
常量,请不要使用JDBC-ODBC桥驱动程序连接到Oracle。 Better still, don't use the JDBC-ODBC bridge driver to connect to Oracle. 更好的是,不要使用JDBC-ODBC桥驱动程序来连接到Oracle。
That's because you have an IN OUT parameter, so you must set the IN, for example: 那是因为您有一个IN OUT参数,因此必须设置IN,例如:
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. 有一个问题,就是光标IN不能用作IN参数。 Are you really going to send a refcursor as parameter? 您是否真的要发送refcursor作为参数?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.