首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Spring JdbcTemplate queryForList()有关问题

2012-01-02 
Spring JdbcTemplate queryForList()问题测试程序片段如下:ApplicationContextcontextnewFileSystemXmlAp

Spring JdbcTemplate queryForList()问题
测试程序片段如下:

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

不解特来此请教达人,希望知道的各位兄弟   不吝指教.

[解决办法]
呵呵.刚好碰上这个问题,你吧HashMap对象换成Map对象就可以了,哦,给分啊.;)

热点排行