我试图设置一个使用函数的轮询器,该函数返回一个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()
思考? 提前谢谢!
答案 0 :(得分:1)
? = call FN_MY_FUNCTION()
在这种情况下,无效语法,请尝试:
SELECT FN_MY_FUNCTION()FROM DUAL
并从结果集中获取结果。
答案 1 :(得分:1)
从我这边我可以和你分享这样的事情:
<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"/>
我看到了相同的程序编译结果,但现在调用了Exception:
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
扩展程序。
让我知道它是否像其他方式一样。