我正在處理Spring 2.5 MVC模塊,我使用模板從數據庫中獲取數據並返回列表...在列表中,我添加了Bean對象現在當我試圖從bean對象的顯示ClassCastException
爲什麼這段代碼在Java中拋出ClassCastException Spring MVC
List listLogin = LoginDao.Authenticate(username,password);
Iterator it = listLogin.iterator();
while (it.hasNext())
{
Login bean1= (Login) it.next(); //here it is showing classCastException
System.out.println(bean1.getClinicId());
}
public static List Authenticate(String userName, String password) {
List names = template.query("select clinicId from doc_user where userName='"+userName+"' and passwd='"+password+"'",
new RowMapper() {
public Object mapRow(ResultSet resultSet, int i) throws SQLException
{
ArrayList lst = new ArrayList();
Login loginBean = new Login();
loginBean.setClinicId(String.valueOf(resultSet.getInt(1)));
lst.add(loginBean);
return lst;
}
});
return names;
}
作爲一個說明,將來還會發布異常的堆棧跟蹤。 – 2012-03-29 17:01:38