I am trying to execute an SQL Function using Spring JDBC.
My code is
SimpleJdbcCall caller = new SimpleJdbcCall(this.jdbcTemplateRandOnline).withCatalogName("RATELIMIT_OWN").withFunctionName("Get_Logs");
RateLimitLogBean resultBean = null;
SqlParameterSource paramMap = new MapSqlParameterSource().addValue(P_YYYYMM, inputBean.getMonth(), Types.VARCHAR).addValue(P_NUMEC, inputBean.getNumec(), Types.INTEGER);
resultBean = caller.executeFunction(RateLimitLogBean.class, paramMap);
but when I run this code, I am getting below error
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call RATELIMIT_OWN.GET_LOGS()}];
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 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1030) at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1064) at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:388) at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:351) at org.springframework.jdbc.core.simple.SimpleJdbcCall.executeFunction(SimpleJdbcCall.java:154)
I couldn't understand why it's throwing this error. For prepared statements we declare input and output params and compile them. But for functions, how can we compile when we are passing it as SqlParamSource
Sql Function
FUNCTION RATELIMIT_OWN.Get_Logs ( p_yyyymm VARCHAR2, p_numec NUMBER )
This function returns records of type
TYPE RATELIMIT_OWN.LOG_RECORD AS OBJECT
(EVENTID VARCHAR2(15),
MSG VARCHAR2(2000),
CREATE_DATE DATE);
I have debugged to Spring framework. What I found is, in
org.springframework.jdbc.core.metadata.CallMetaDataContext.reconcileParameters method, I am getting this.metaDataProvider.getCallParameterMetaData() this arraylist with all values are null.
Any reason?
Best Answer
You need to add
To your SimpleJdbcCall.