2

//设置输入参数

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

1 回答 1

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;
}
}
于 2012-04-24T06:31:31.363 回答