赞
踩
使用hibernate框架,hql语言,mysql数据库,在做查询的时候遇到一个问题,发现查询的条件为空,但是查询总是报错。原因是当条件为空时,条件上应该用 is not,而不是这样
- Query query_getMoney = session1.createQuery("select sum(" + sqlField_Summation + ") from Lshsje where spNo1 = :a and spNo2 = :b and itemNo = :c");
- query_getMoney.setString("a", sp1No);
- query_getMoney.setString("b", null);
- query_getMoney.setString("c", itemNo);
- money = (double) query_getMoney.uniqueResult();
改成这样就好了
- Query query_getMoney = session1.createQuery("select sum(" + sqlField_Summation + ") from Lshsje where spNo1 = :a and spNo2 is null and itemNo = :c");
- query_getMoney.setString("a", sp1No);
- query_getMoney.setString("c", itemNo);
- money = (double) query_getMoney.uniqueResult();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。