PROCEDURE的参数数量不正确;预期1,得到0.不能从代码中确定错误

时间:2012-04-22 19:16:50

标签: spring stored-procedures jdbc spring-jdbc

//设置输入参数

Map<String,Object> inParams = new HashMap<String,Object>();
inParams.put("Sig",resourceHistoryBean.getId());

List<ResourceHistoryBean> resourceHistoryList= new ArrayList<ResourceHistoryBean>();

//定义存储过程

try{        
    SimpleJdbcCall readResult = new SimpleJdbcCall(getDataSource())
            .useInParameterNames("Sig")
            .declareParameters(new SqlParameter("Sig", Types.VARCHAR))
            .withProcedureName("SP_ResourceAllocationDtls")
            .withSchemaName("hrms")
            .returningResultSet("ResourceHistory", new ParameterizedRowMapper<ResourceHistoryBean>() {
                public ResourceHistoryBean mapRow(ResultSet rs, int rowNum)
                        throws SQLException {
                    ResourceHistoryBean bean = new ResourceHistoryBean();
                    resourceHistoryBean.setProjectName(rs.getString(RH_PROJECT_NAME));
                    return bean;
                }
            });
    readResult.compile();

//执行存储过程

Map<String, Object> out = readResult.execute(inParams);
resourceHistoryList = (List<ResourceHistoryBean>) out.get("ResourceHistory");

1 个答案:

答案 0 :(得分:1)

看起来我能够找到上述问题的替代解决方案(参数传递给存储过程并使用映射类):

public List<ResourceHistoryBean> getResourceHistory(final ResourceHistoryBean resourceHistoryBean)throws Exception{

    try {
        // call stored procedure and pass parameter to it
        List resourceHistoryList = getJdbcTemplate().query(
                "call hrms.SP_ResourceAllocationDtls(?)",
                new Object[] {resourceHistoryBean.getId()}, new HistoryMapper());
        return resourceHistoryList;
    } catch (Exception e) {
        throw e;
    } finally {
        closeTemplate();

    }

}

// mapper class

class HistoryMapper implements RowMapper, IDatabaseConstants {

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    ResourceHistoryBean resourceHistoryBean = new ResourceHistoryBean();
    resourceHistoryBean.setProjectName(rs.getString(RH_PROJECT_NAME));
    return resourceHistoryBean;
}
}