【问题标题】:Incorrect number of arguments for PROCEDURE; expected 1, got 0. Cant determine the error from codePROCEDURE 的参数数量不正确;预期为 1,得到 0。无法从代码中确定错误
【发布时间】:2012-04-22 19:16:50
【问题描述】:

//设置输入参数

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");

【问题讨论】:

    标签: spring stored-procedures jdbc spring-jdbc


    【解决方案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();
    
        }
    
    }
    

    // 映射器类

    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;
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-20
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多