2012-04-22 2 views
2

// 설정된 입력 파라미터PROCEDURE의 인수 개수가 잘못되었습니다. 1 예상 캔트 코드에서 에러를 결정 0.있어

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

위의 문제 (매개 변수를 저장 프로 시저에 전달하고 매핑 클래스도 사용)에 대한 대체 솔루션을 찾을 수 있었던 것 같습니다 :

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; 
} 
} 
관련 문제