我是新手使用jdbc
,我有一些问题。
我用hql在MySQL中搜索数据,结果是Query
type。我不知道如何从“查询”中获取数据。这是我的代码:
final String hql = "select app.appkey,app.type from " + getClassName() +
"app where app.appkey<>'no-appkey' group by app.type";
Query query = getEntityManager().createQuery(hql);
非常感谢。
如果您期待结果列表,那么:
List<Object[]> results = query.getResultList();
如果您期望一个结果:
Object[] result = query.getSingleResult(); // if more than one result was found, this method will throw a NonUniqueResultException
如果列信息将存储在 Object 数组的某个位置。例子:
String appKey = (String) result[0];
String appType = (String) result[1];
但是使用 Object 数组并不好。尝试使用 Dto,就像这里解释的那样。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句