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语句!怎么样这样的查询遍历出来!谁能告诉我呀!

解决方案 »

  1.   

    用 for 循环遍历结果集
      

  2.   

    你先写一个bean把用于保存每一条返回的记录
    然后再将bean ,add到ArrayList中去,然后用它的iterator迭代器遍历整个ArrayList中的bean
      

  3.   

    能写出来吗!我刚刚接触Hibernate!谢谢了
      

  4.   

    我说半天你不知道这个是Hibernate吗??
      

  5.   

    你可以参考这个
       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();
       }
      

  6.   

    你是指要遍历这两个PO的所有属性,通过HQL将其分别取出来吗?
    如果是这样的话那么你可以用反射来做啊,很方便的啦。
      

  7.   


    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));
    }
    }
      

  8.   

    一:
    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顺序与类型
    }