Spring 集成 - 仅带 out 参数的存储过程入站通道适配器函数抛出“缺少 IN 或 OUT 参数”

Spring Integration - stored-proc-inbound-channel-adapter with out parameter only function throws " Missing IN or OUT parameter"

我正在尝试设置一个轮询器,该轮询器使用一个函数,该函数 returns 一个 varchar 指示是否是开始作业的时间。我设置了一个输出参数,但它似乎不正确,因为我收到以下错误:

2015-10-01 16:30:44,413 ERROR [task-scheduler-3] org.springframework.integration.handler.LoggingHandler - org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call FN_MY_FUNCTION()}]; SQL state [99999]; error code [17041]; Missing IN or OUT parameter at index:: 1; nested exception is java.sql.SQLException: Missing IN or OUT parameter at index:: 1

我不确定为什么会收到此错误。这是我的适配器定义:

  <!-- JDBC polling channel adapter -->
  <int-jdbc:stored-proc-inbound-channel-adapter 
    auto-startup="false" 
    id="jobControlPollingChannelAdapter"
    data-source="dataSource"
    channel="outputChannel"
    expect-single-result="true"
    is-function="true"
    stored-procedure-name="${outbound.feed.db.polling.sp}"
  >

    <int:poller default="false" id="jdbcPoller" fixed-delay="5000" time-unit="MILLISECONDS"/>
    <int-jdbc:sql-parameter-definition name="completionStatus" direction="OUT" type="VARCHAR"/>
    <int-jdbc:returning-resultset name="outboundRunCheckResult" row-mapper="outboundRunCheckMapper" />
  </int-jdbc:stored-proc-inbound-channel-adapter>

函数调用很简单:

? = call FN_MY_FUNCTION()

想法? 提前致谢!

? = call FN_MY_FUNCTION()

在这种情况下是无效语法,请尝试:

SELECT FN_MY_FUNCTION() 来自双

并从结果集中得到结果。

在我这边,我可以和你分享这样的东西:

<int-jdbc:stored-proc-inbound-channel-adapter id="inbound-adapter" channel="outputChannel" data-source="dataSource"
    ignore-column-meta-data="true"
    expect-single-result="true"
    stored-procedure-name="GET_RANDOM_NUMBER"
     is-function="true">
    <int-jdbc:returning-resultset name="out" row-mapper="org.springframework.jdbc.core.SingleColumnRowMapper"/>
</int-jdbc:stored-proc-inbound-channel-adapter>

其中程序是这样的:

17:43:06,036 DEBUG task-scheduler-1 simple.SimpleJdbcCall:313 - Compiled stored procedure. Call string is [{? = call GET_RANDOM_NUMBER()}]
17:43:06,037 DEBUG task-scheduler-1 simple.SimpleJdbcCall:289 - SqlCall for function [GET_RANDOM_NUMBER] compiled
17:43:06,039 DEBUG task-scheduler-1 metadata.CallMetaDataContext:500 - Matching [] with []
17:43:06,039 DEBUG task-scheduler-1 metadata.CallMetaDataContext:501 - Found match for []
17:43:06,041 DEBUG task-scheduler-1 simple.SimpleJdbcCall:395 - The following parameters are used for call {? = call GET_RANDOM_NUMBER()} with {}
17:43:06,041 DEBUG task-scheduler-1 simple.SimpleJdbcCall:398 - 1: out, SQL type 0, type name null, parameter class [org.springframework.jdbc.core.SqlReturnResultSet]
17:43:06,042 DEBUG task-scheduler-1 core.JdbcTemplate:1062 - Calling stored procedure [{? = call GET_RANDOM_NUMBER()}]

如果我添加这个:

<int-jdbc:sql-parameter-definition name="out" direction="OUT" type="DECIMAL"/>

我看到相同的程序编译结果,但现在调用时出现异常:

17:44:09,141 ERROR task-scheduler-1 handler.LoggingHandler:145 - org.springframework.dao.DataIntegrityViolationException: CallableStatementCallback; SQL [{? = call GET_RANDOM_NUMBER()}]; ??? ??????
No data is available [2000-180]; nested exception is org.h2.jdbc.JdbcSQLException: ??? ??????
No data is available [2000-180]
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:102)

是的,这是不同的问题,但你应该从这里看出你的 sql-parameter-definition 是有罪的。

换句话说,returning-resultset 无论如何指定过程调用的参数。请参阅 org.springframework.jdbc.core.SqlReturnResultSet SqlParameter 扩展名。

让我知道是否像其他方式一样。