Spring JdbcTemplate queryForList()问题

周口店的程序猿 2007-02-10 11:42:30
测试程序片段如下:

ApplicationContext context = new FileSystemXmlApplicationContext("beans-config.xml");
DataSource ds = (DataSource)context.getBean("dataSource");
JdbcTemplate jt = new JdbcTemplate(ds);
List list = jt.queryForList("select fname,lname from employee");
java.util.Iterator<HashMap> it = list.iterator();
while(it.hasNext()){
HashMap map = it.next();
System.out.println((String)map.get("fname")+(String)map.get("fname"));
}


编译正常通过,执行的时候发现错误(貌似一定要用apache集合包?)
错误信息如下:
Exception in thread "main" java.lang.ClassCastException: org.apache.commons.collections.map.ListOrderedMap

不解特来此请教达人,希望知道的各位兄弟 不吝指教.
...全文
1183 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuxu000 2009-12-04
  • 打赏
  • 举报
回复
呵呵,持续关注中!!
风月无边 2008-05-22
  • 打赏
  • 举报
回复
呵呵.刚好碰上这个问题,你吧HashMap对象换成Map对象就可以了,哦,给分啊.;)
  • 打赏
  • 举报
回复
顶下

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧