String sql = "select count(infection_infectionType) as infeNum, infection_infectiontype "
+" from "+ tabName
+" where infection_takendate between ? and ? " + conditions
             +" group by infection_infectiontype "
                   +" order by infeNum DESC";
session = sessionFactory.getCurrentSession(); Query query = session.createSQLQuery(sql);
query.setString(0, fromTime);
query.setString(1, toTime);
return query.list();
每种infection_infectionType 的条数  和  infection_infectionType 名字。  
然后怎么取出来 从list中取出来?

解决方案 »

  1.   

    你的这条SQL的返回值是一个二维的object数组、双层for循环遍历就能取

    LZ可以试试
      

  2.   

    System.out.println("查询"+tabName+"表,从"+fromTime+"至"+toTime+"间病例");
    String sql = "select count(infection_infectionType) as infeNum, infection_infectiontype "
    +" from "+ tabName
    +" where infection_takendate between ? and ? " + conditions
                 +" group by infection_infectiontype "
                       +" order by infeNum DESC";
    session = sessionFactory.getCurrentSession();
    Query query = session.createSQLQuery(sql);
    query.setString(0, fromTime);
    query.setString(1, toTime);

    List<Object> result = query.list();
    List<InfeNumDTO> returnR = new ArrayList<InfeNumDTO>();
    Iterator<Object> it = result.iterator();       
    while (it.hasNext()) {
    InfeNumDTO ind = new InfeNumDTO();
    Object[] obj = (Object[]) it.next();
    int infeNum = Integer.parseInt(obj[0].toString());
    ind.setInfeNum(infeNum);       
    ind.setInfeName(obj[1].toString());
    returnR.add(ind);
    }

    return returnR;
    解决了