如何取List中的值
public static List GetDataList(String sql)
{
Session session;
SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
List l=session.createQuery(sql).list();
session.close();
sessionFactory.close();
return l;
}
//id 是字符串 sl 是数字double型
String sid;
double ssl;
String sql="select id,sl from Kc " ;
List l =null;
l = df.GetValue.GetDataList(sql);
String sss=l.get(0).toString();//这么取不到
String dd=l.get(1).toString();
jsbc = sl;
Iterator iter1 = l.iterator();
if (iter1.hasNext()) {
String ss[]=new String[2];
ss = (String[]) iter1.next(); //这么取不对
}
问怎么才能把id,sl的值取出来到 sid,ssl里
------解决方案--------------------------------------------------------
if (l.size() > 0){
ListOrderedMap map = (ListOrderedMap) l.get(0);
sid = map.getValue(0).toString();
ssl = Double.parseDouble(map.getValue(1).toString();)
}
------解决方案--------------------------------------------------------
你可以用hashmap把id和sl put进去然后再取却出来
------解决方案--------------------------------------------------------
用Object[]