2014-01-27 20 views
0

我正在学习在java中使用存储过程。早些时候,我使用JDBC模板,我能够从数据库中获取值。 现在我有一个错误:收集对象不能转换为列表类错误 - 收集<Object>不能转换为列表<Class>

有没有什么办法可以将Collection(Object)转换为List(Class)?

是我的模型类

我的存储过程类

public class ListRegistration extends StoredProcedure { 
    @Autowired 
    private DataSource dataSource; 
    private static final String SCHEMA_NAME = "ehr"; 
    private static final String SPROC_NAME = "ehr.usp_ListRegistration"; 

    public DataSource getDataSource() { 
     return dataSource; 
    } 

    public ListRegistration(DataSource dataSource) { 
     super(dataSource, SPROC_NAME); 
     declareParameter(new SqlReturnResultSet("rs", new BeanPropertyRowMapper(Patient.class))); 
     declareParameter(new SqlParameter("LimitRows", Types.INTEGER)); 
     compile(); 
    } 
public List<Patient> spExecute(Integer LimitRows) 
{ 

    Map<String, Object> registrationResult=new HashMap<String,Object>(); 
    registrationResult = super.execute(LimitRows); 

    List<Patient> patientList = new ArrayList<Patient>; 
patientList = registrationResult.values(); 
     return patientList; 
} 

}

List<Patient> patientList = new ArrayList<Patient>; 
    patientList = registrationResult.values(); 

这是我的错误。

在我implementaion类我有

public List<Patient> getPatient() { 
    System.out.println("============================ Will Fetch Values "); 
    List<Patient> patientList = new ArrayList<Patient>(); 
    int t=100; 
     patientList=listRegistration.spExecute(100); 
     return patientList; 
    } 
+0

可否请您发布您的StoredProcedure类 –

+0

我已经给出了上面的存储过程类。 –

回答

0

values()返回一组,而不是一个列表。

你能虽然做的是:

List<Patient> patients = new ArrayList(registrationResults.values()); 

这将创建一个新的列表,并与返回键填充它。

为什么你确实需要这样做?如果您只是使用values作为CollectionSet,则代码将更有效。

相关问题