QBC查询方式可以用Projection.avg(),rowCount()、count(),max(),min,CountDistinct()等方法来实现统计查询
hql查询方式:"select count(*),min(userId) from user as u "这样的查询语句
例如:
Query query=session.CreateQuery("select count(*),min(userId) from user as u ");
Iterator it=query.list.iterator();while(it.hasNext())
{
Object[] obj=(Object[])it.next();
System.out.println(obj[0]);//这个是count
System.out.println(obj[1]);//这个是最小的userId,你可以把这个object转换为String Integer等对象
}
因为都是手打,没有在IDE里测试,如果有拼写错误,请原谅则个

解决方案 »

  1.   

    count max min sum avg,没有写出来的都是同样的道理,请参照我上边说的
      

  2.   

    楼上的如果对象是Float怎么转啊?
      

  3.   

    我上实验课的时候用的这个,测试成功了org.hibernate.Session hSession = new Configuration().configure().buildSessionFactory().openSession();
    Query query = hSession.createSQLQuery("select count(*) from Vnews");
    Integer totalCount = Integer.parseInt(query.list().iterator().next().toString());
      

  4.   

    int l=((Long)session.createQuery("select count(*) from Staff").uniqueResult()).intValue(); 
    改成
    int l=((Long)session.createQuery("select count(s.*) from Staff s").uniqueResult()).intValue(); 
      

  5.   

    肯定不会自动将l的值打印出来的。
    再说了,打印出来了有什么用啊,真那么想打印出来自己写syso啊。
      

  6.   


    Query count=session.createQuery("select count(*) from Staff");
    String str=count.list().toString();
    char[] c=str.toCharArray();
    //把[m]拆分成m
    StringBuffer sb=new StringBuffer();
    for(int i=1;i<c.length-1;i++){
    sb.append(c[i]);
    }//拆分出m条总记录啦
    System.out.println(sb.toString());本人初学者,不知道符合你的要求不.