日期:2014-05-18  浏览次数:20615 次

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对象就可以了,哦,给分啊.;)