select Checi.checi,Checi.shifa,Checi.kaiche,Huoche.chezhan,Huoche.daoda,Huoche.yunxing,Huoche.licheng,Huoche.yingzuo,Huoche.ruanzuo,
Huoche.yingwo,Huoche.ruanwo from Checi as c,Huoche as h where c.checi=h.checi and c.shifa like '"+北京+"%' and h.chezhan like '"+上海+"%'"; 我有这么一条HQL语句!怎么样这样的查询遍历出来!谁能告诉我呀!
Huoche.yingwo,Huoche.ruanwo from Checi as c,Huoche as h where c.checi=h.checi and c.shifa like '"+北京+"%' and h.chezhan like '"+上海+"%'"; 我有这么一条HQL语句!怎么样这样的查询遍历出来!谁能告诉我呀!
然后再将bean ,add到ArrayList中去,然后用它的iterator迭代器遍历整个ArrayList中的bean
for(int i=0;i<result.length;i++){
int j=1;
result[i] = new UserDO();
result[i].setUserID(sqlRst.getInt(j++));
result[i].setUserName(sqlRst.getString(j++));
result[i].setActive(sqlRst.getString(j++).equals("A") ? true : false);
result[i].setAccountID(sqlRst.getInt(j++));
sqlRst.next();
}
如果是这样的话那么你可以用反射来做啊,很方便的啦。
Statement ps = conn.createStatement();
String sql = "select Checi.checi,Checi.shifa,Checi.kaiche,Huoche.chezhan,Huoche.daoda,Huoche.yunxing,Huoche.licheng,Huoche.yingzuo,Huoche.ruanzuo, "+
" Huoche.yingwo,Huoche.ruanwo from Checi as c,Huoche as h where c.checi=h.checi and c.shifa like '北京%' and h.chezhan like '上海%'";
ResultSet rs = ps.executeQuery(sql);
ResultSetMetaData rm = rs.getMetaData();
int column = rm.getColumnCount();
while(rs.next()) {
for(int i=1;i<=column;i++) {
System.out.println(rm.getColumnLabel(i)+":"+rs.getObject(i));
}
}
HQL里的中文小心点.这样可能得不到正确的结果二:这样的HQL语句的结果不再是对像,list里的每一个对像是一个Object[]数组
Iterator it = query.list().iterator();while(it.hasNext())
{
Object[] o = (Object[])it.next();
//然后对照你的HQL顺序,改是String就String s = (String)o[0];或者是Integer i = (Integer)o[3];这样都看到你select顺序与类型
}