简体   繁体   English

无法访问存储过程的OUT参数

[英]Unable to access stored procedure's OUT parameter

We are the moment trying to use a stored procedure from our Java code through Toplink but we seem to have an issue there I haven't been able to find an answer to. 我们现在正尝试通过Toplink使用Java代码中的存储过程,但似乎有一个问题,我无法找到答案。 It might be that my Google-Fu is failing me in this instance. 在这种情况下,可能是我的Google-Fu使我失败了。

Our problem is that while the procedure seems to be invoked correctly we get nothing back to the Java code. 我们的问题是,虽然该过程似乎被正确调用,但我们什么也得不到Java代码。 The procedure in question has been tested from SQLDeveloper with the same input parameters and the procedure returns values as it should. 已使用相同的输入参数从SQLDeveloper中测试了该过程,该过程将返回应有的值。

The procedure signature is 程序签名是

create or replace PACKAGE FORM_METADATA AS
  PROCEDURE FORM_LIST_GET (
      P_USER_ID IN VARCHAR2,
      P_CHANNEL_NO IN NUMBER,
      P_START_FROM IN NUMBER, --pagination
      P_COUNT_TO_RETURN IN NUMBER,  --pagination
      P_GET_TOTAL_COUNT IN NUMBER, -- if total count should be returned then 1, other wise 0
      P_RESULT_SET OUT  SYS_REFCURSOR,
      P_TOTAL_COUNT OUT NUMBER);
end FORM_METADATA;

The Java code invoking this procedure looks like this: BigDecimal count = new BigDecimal(-1); 调用此过程的Java代码如下所示:BigDecimal count = new BigDecimal(-1);

Session session = getSession();
session.setLog(new OutputStreamWriter(System.out));
session.setLogLevel(SessionLog.FINEST);
StoredProcedureCall procedureCall = new StoredProcedureCall();
procedureCall.setProcedureName("FORM_METADATA.FORM_LIST_GET");
procedureCall.addNamedArgumentValue("P_USER_ID", "UserID-1");
procedureCall.addNamedArgumentValue("P_CHANNEL_NO", new BigDecimal(1));
procedureCall.addNamedArgumentValue("P_START_FROM", new BigDecimal(1));
procedureCall.addNamedArgumentValue("P_COUNT_TO_RETURN", new BigDecimal(1000));
procedureCall.addNamedArgumentValue("P_GET_TOTAL_COUNT", new BigDecimal(1));

procedureCall.useNamedCursorOutputAsResultSet("P_RESULT_SET");
procedureCall.addNamedOutputArgument("P_TOTAL_COUNT", "count", BigDecimal.class);

DataReadQuery dq = new DataReadQuery();
dq.setCall(procedureCall);
dq.prepareForExecution();

Object result = session.executeQuery(dq);
System.out.println("Result:: " + result);
System.out.println("Result from StoredProcedreCall: " + procedureCall.getResult());

The output we are receiving looks like this: 我们收到的输出如下所示:

[TopLink Warning]: 2015.08.31 16:11:30.781--Failed to get InitialContext for MBean registration: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
[TopLink Warning]: 2015.08.31 16:11:30.797--Failed to get InitialContext for MBean registration: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
[TopLink Info]: 2015.08.31 16:11:31.685--DatabaseSessionImpl(1827000661)--TopLink, version: Oracle TopLink - 11g Release 1 (11.1.1.5.0) (Build 110305)
[TopLink Info]: 2015.08.31 16:11:34.147--DatabaseSessionImpl(1827000661)--dev login successful
[TopLink Finest]: 2015.08.31 16:11:34.147--DatabaseSessionImpl(1827000661)--Thread(Thread[main,5,main])--Execute query DataReadQuery()
[TopLink Finest]: 2015.08.31 16:11:34.163--DatabaseSessionImpl(1827000661)--Thread(Thread[main,5,main])--reconnecting to external connection pool
[TopLink Fine]: 2015.08.31 16:11:34.227--DatabaseSessionImpl(1827000661)--Connection(1635575430)--Thread(Thread[main,5,main])--BEGIN FORM_METADATA.FORM_LIST_GET(P_USER_ID=>?, P_CHANNEL_NO=>?, P_START_FROM=>?, P_COUNT_TO_RETURN=>?, P_GET_TOTAL_COUNT=>?, P_RESULT_SET=>?, P_TOTAL_COUNT=>?); END;
  bind => [UserID-1, 1, 1, 1000, 1, => P_RESULT_SET, => P_TOTAL_COUNT]
Result:: []
Result from StoredProcedreCall: null
Process exited with exit code 0.

I'm fairly sure our problem is with the Java code invoking the procedure but as I said, we haven't been able to find the correct solution yet. 我相当确定我们的问题是Java代码调用了该过程,但是正如我所说的,我们尚未能够找到正确的解决方案。 Would anyone have a pointer as to where we should start looking next? 有人会指出我们应该从哪里开始寻找下一个目标吗?

Thank you in advance, 先感谢您,
Mika 米卡


Update: 更新:

A colleague of mine managed to find the reason why the procedure didn't seem to return anything. 我的一位同事设法找到了该程序似乎未返回任何内容的原因。 For brevity I had redacted a couple of parameters which we were not used in this instance and which we did not believe to be the reason for the perceived behaviour. 为简洁起见,我已删除了一些我们在本例中未使用的参数,我们认为这些参数不是造成这种可感知行为的原因。 However, as the parameters were mandatory these were set to NULL. 但是,由于参数是强制性的,因此将它们设置为NULL。 My colleague thought to try initializing the parameters without value and after that the query returned a set of data that was expected. 我的同事想尝试初始化没有值的参数,然后查询返回了一组期望的数据。

So our code change (in Java) was to go from 所以我们的代码更改(在Java中)是从

procedureCall.addNamedArgumentValue("P_ORDER_BY", OracleTypes.NULL);

to

procedureCall.addNamedArgument("P_ORDER_BY");

Now we get the data from the cursor as expected but the second out parameter's value still eludes us. 现在,我们可以按预期从游标获取数据,但是秒出参数的值仍然难以理解。

在更集中地搜索第二个参数之后,我们在Oracle论坛中找到了该线程 ,这为我们提供了所需的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JDBI支持带out参数的存储过程 - JDBI supports stored procedure with out parameter 错误:未为存储过程定义参数输出 - Error: Parameter out was not defined for stored procedure Java存储过程中需要使用OUT参数的MYSQL - needed in java stored procedure with OUT parameter for MYSQL 通过CallableStatement调用存储过程时出现“参数不是OUT参数”错误 - “Parameter is not an OUT parameter” error while calling stored procedure via CallableStatement JDBC MySQL存储过程抛出异常“参数编号2不是OUT参数”吗? - JDBC MySQL stored procedure throw exception “ Parameter number 2 is not an OUT parameter”? Mybatis在执行存储过程时无法设置OUT参数 - Mybatis could not set OUT parameter when executing stored procedure 执行存储过程并在Hibernate中获取单输出参数 - Execute a stored procedure and get single out parameter in Hibernate 使用jpa 2.0调用具有out参数的存储过程 - calling a stored procedure having out parameter using jpa 2.0 获取存储过程的十进制输出参数时的JDBC异常 - JDBC exception at getting decimal out parameter of stored procedure 从存储过程中捕获out参数以传递给Shell脚本 - Capture the out parameter from stored procedure to pass to shell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM