HQL Query来检查表是否有数据 [英] HQL Query to check whether table has data or not
本文介绍了HQL Query来检查表是否有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最初数据库创建它没有任何表。我使用参数化查询编写了更新值的代码,但是值最初并不存在,那我们该如何处理它?<b>
Initially database created it doesn't have any table. I write code to update values using parameterised query but value doesn't exist initially then how we can handle it?
推荐答案
试试这样:
You can try like this:
public Boolean existsOrNot (DTOAny i) {
Query q = getSession().
createQuery("select 1 from DTOAny t where t.key = :key");
q.setString("key", i.getKey() );
return (q.uniqueResult() != null);
}
(假设表存在并且您正在检查是否存在表中的数据或不是)
这篇关于HQL Query来检查表是否有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文