Java Hibernate查询带函数计数
我正在学习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 {
"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的用户数