这是我的程序代码: 规范:
create or replace PACKAGE PKG_NALD AS
PROCEDURE PROC_KETQUA(res OUT SYS_REFCURSOR ,maMH STRING);
END PKG_NALD;
身体:
create or replace PACKAGE BODY PKG_NALD AS
PROCEDURE PROC_KETQUA(res OUT SYS_REFCURSOR ,maMH STRING) AS
BEGIN
OPEN res FOR
select MA_MH as maMH123, TEN_MH as tenMH, TIN_CHI as tinChi, KHOA as khoa from nald_mon_hoc where upper(ma_mh) = upper(maMH);
END PROC_KETQUA;
END PKG_NALD;
这是我的代码,以便通过 CallableStatement 调用过程:
String sqlQuery = "call PKG_NALD.PROC_KETQUA(?, :maMH)";
Connection connection = ((SessionImpl)session).connection();
CallableStatement callable = connection.prepareCall(sqlQuery);
callable.setObject (2, "COSC1310", Types.VARCHAR); // This method belongs to java.sql.PreparedStatement
callable.registerOutParameter(1, OracleTypes.CURSOR);
callable.execute();
程序可以正常运行。但是,如果我将 callable.setObject (2, "COSC1310", Types.VARCHAR) 替换为
callable.setObject("maMH", "COSC1310", Types.VARCHAR); // This method belongs to java.sql.CallableStatement
我收到错误:
Exception in thread "main" java.sql.SQLException: The number of parameter names does not match the number of registered praremeters
at oracle.jdbc.driver.OracleSql.setNamedParameters(OracleSql.java:196)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4708)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)
at com.mkyong.util.QueryUtil.getListFromPackage(QueryUtil.java:71)
at com.mkyong.App.main(App.java:35)
尽管这里有文件,但还是出了点问题。我应该怎么办 ?