SQL不等于问题

xiyaoponewnew 2016-08-04 02:08:00
String hql="from GdzcView g where g.gongSi = ?";
if(Integer.parseInt(qzaiyong)==0){
hql+=" and g.zhuanTai <> 1";
}
if(Integer.parseInt(qkuchun)==0){
hql+=" and g.zhuanTai <> 0";
}
if(Integer.parseInt(qbaofei)==0){
hql+=" and g.zhuanTai <> 2";
}
得出的结果是
from GdzcView g where g.gongSi = ? and g.zhuanTai <> 1 and g.zhuanTai <> 0
因为 qbaofei=1 本想会只留下g.zhuanTai =2的,但是无效,全出来,请高手说说或帮忙改改,叩谢
...全文
356 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
方丈的寺院 2016-08-05
  • 打赏
  • 举报
回复
@xiyaoponewnew 用的什么数据库,既然得到的SQL 语句是你想要的。查询的结果不是你想要的。 那么直接拿着SQL 去数据库执行先验证下
xiyaoponewnew 2016-08-04
  • 打赏
  • 举报
回复
感谢上面两位回复 得到hql = "from GdzcView g where g.gongSi = ? and g.zhuanTai <> 1 and g.zhuanTai <> 0"是对的 但执行后g.zhuanTai = 1和g.zhuanTai = 0,g.zhuanTai = 2的数据全部到检索出来,我怀疑hql能不能这样写。
kahnyy5202015 2016-08-04
  • 打赏
  • 举报
回复
qzaiyong qkuchun 得到的值 qbaofei=1 所以integer......qbaofei==0 不成立 所以没有and g.zhuanTai <> 2
会飞的大楼 2016-08-04
  • 打赏
  • 举报
回复
qbaofei = 1 使用 Integer.parseInt(qbaofei)==0 当然是false,hql 就不会加上+=" and g.zhuanTai <> 2"; 如果前面两个都是true的话hql = "from GdzcView g where g.gongSi = ? and g.zhuanTai <> 1 and g.zhuanTai <> 0" 这不是很正确?不等于0并且不等于1 这不就是等2吗。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧