Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate查询带函数计数_Java_Sql_Hibernate_Count - Fatal编程技术网

Java Hibernate查询带函数计数

Java Hibernate查询带函数计数,java,sql,hibernate,count,Java,Sql,Hibernate,Count,我正在学习Hibernate,在一个练习中,我必须做这个查询 "SELECT count(id) as numero_utenti, imc FROM Utenti WHERE azienda = '" + id + "' GROUP BY imc" 问题是,我不知道如何查看结果并将结果保存为字符串 谢谢 这就是函数 public String getStat(int id) { String stat = ""; int count = 0; try {

我正在学习Hibernate,在一个练习中,我必须做这个查询

"SELECT count(id) as numero_utenti, imc 
FROM Utenti 
WHERE azienda = '" + id + "' GROUP BY imc"
问题是,我不知道如何查看结果并将结果保存为字符串

谢谢

这就是函数

public String getStat(int id) {

    String stat = "";
    int count = 0;
    try {
        Query query = session.createQuery("SELECT count(id) as numero_utenti, imc FROM Utenti WHERE azienda = '" + id + "' GROUP BY imc");

        // as I extract the values​​?


        tx.commit();
    } catch (HibernateException he) {
        throw he;
    } 

    return stat;
}

如果您正在查看如何使用hibernate会话执行查询。 query=session.createQuery(“semect*from temp”); 和查询实例 Long.valueOf(query.fetchCountOfRows()).intValue();
它将为您提供行数。

如果它们不是唯一的,请获取列表

List<String> imcs= null;
int count = 0;

Query query = session.createQuery("SELECT imc FROM Utenti WHERE azienda = '" + id + "' GROUP BY imc");
imcs = query.list();
count = imcs.size();
List imcs=null;
整数计数=0;
Query Query=session.createQuery(“从Utenti中选择imc,其中azienda='”+id+“'GROUP BY imc”);
imcs=query.list();
计数=imcs.size();

请正确提问。这是不可理解的。我已经更新了postsorry,但查询没有fetchCountOfRows功能。我想打印按IMC分组的用户数。我的查询返回n行,其中包含IMC=X的用户数