spring ArrayIndexOutOfBoundsException with SimpleJdbcCall

北慕城南 提交于 2019-12-06 15:17:19

The issue is here

Map m = procGetReportExtras.execute(new HashMap<String, Object>(0), in);

You are calling the overloaded method that takes in a Object .... This method takes

optional array containing the in parameter values to be used in the call. Parameter values must be provided in the same order as the parameters are defined for the stored procedure.

In your call, those two parameters happen to be an empty HashMap and a SqlParameterSource.

The call fails in CallMetaDataContext#matchInParameterValuesWithCallParameters(). Source:

public Map<String, ?> matchInParameterValuesWithCallParameters(Object[] parameterValues) {
    Map<String, Object> matchedParameters = new HashMap<String, Object>(parameterValues.length);
    int i = 0;
    for (SqlParameter parameter : this.callParameters) {
        if (parameter.isInputValueProvided()) {
            String parameterName =  parameter.getName();
            matchedParameters.put(parameterName, parameterValues[i++]); // fails here
        }
    }
    return matchedParameters;
}

It's expecting that the array you pass has 7 elements (because that's what your stored procedure expects), but it only has 2, the HashMap and the SqlParameterSource. When it tries to access the 3rd one (index 2), it throws an ArrayIndexOutOfBoundsException.

You probably wanted to use the execute() method that accepts an SqlParameterSource

Map m = procGetReportExtras.execute(in);

You are calling the wrong SimpleJDBCCall.execute(Object... args); use SimpleJDBCCall.execute(SqlParameterSource)

procGetReportExtras.execute(in);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!