问个HQL查询写法的问题?

lylshr 2010-07-13 06:10:14
String hql = "FROM WghCustomer AS q where q.customerCode LIKE :customerCode and q.productCode LIKE :productCode and q.generateFlag LIKE :generateFlag and q.weighDate>=? and q.weighDate<=?";
Query q = super.getSession().createQuery(hql);
q.setString("customerCode", "%"+customerCode+"%");
q.setString("productCode", "%"+productCode+"%");
q.setString("generateFlag", "%"+generateFlag+"%");
q.setString(0, startDate);
q.setString(1, endDate);
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);

这样写的HQL报错了,网上说不能把:这种参数和?这种参数一起用,我应该怎么改才好呢?????
...全文
176 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lylshr 2010-07-17
  • 打赏
  • 举报
回复
谢谢大家,我把那个定位参数放前面解决了
elivs_wu 2010-07-14
  • 打赏
  • 举报
回复
String hql = "FROM WghCustomer AS q where q.customerCode LIKE :customerCode and q.productCode LIKE :productCode and q.generateFlag LIKE :generateFlag and q.weighDate>=:startDateand q.weighDate<=:endDate";
Query q = super.getSession().createQuery(hql);
q.setString("customerCode", "%"+customerCode+"%");
q.setString("productCode", "%"+productCode+"%");
q.setString("generateFlag", "%"+generateFlag+"%");
q.setString("startDate", startDate);
q.setString("endDate", endDate);
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);
luomt_1987 2010-07-14
  • 打赏
  • 举报
回复
like语句用4楼的用法好些!
zhangfeng275265586 2010-07-14
  • 打赏
  • 举报
回复
那就都改为一样的啊 要么都是: 要么都是?

不要‘:’和‘?’混合用撒
Jlins 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jerry_bj 的回复:]
LZ 你是做 模糊查询是吗?
建议你用Criteria,它在模糊查询这方面比较方便
日期比较也很方便的
eg:
Criteria criteria = this.getSession(true).createCriteria( 实体类.class);
if (参数!= null)
criteria.add(Expression.like("字段", 参数));
criteria.a……
[/Quote]
+1
ssh87 2010-07-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jerry_bj 的回复:]
LZ 你是做 模糊查询是吗?
建议你用Criteria,它在模糊查询这方面比较方便
日期比较也很方便的
eg:
Criteria criteria = this.getSession(true).createCriteria( 实体类.class);
if (参数!= null)
criteria.add(Expression.like("字段", 参数));
criteria.a……
[/Quote]顶
JerryZhou_ 2010-07-13
  • 打赏
  • 举报
回复
LZ 你是做 模糊查询是吗?
建议你用Criteria,它在模糊查询这方面比较方便
日期比较也很方便的
eg:
Criteria criteria = this.getSession(true).createCriteria( 实体类.class);
if (参数!= null)
criteria.add(Expression.like("字段", 参数));
criteria.add(Expression.ge("rechargeDate", java.sql.Date.valueOf(start)));//start 开始时间
criteria.add(Expression.le("rechargeDate", java.sql.Date.valueOf(end)));//end 结束时间
wzju64676266 2010-07-13
  • 打赏
  • 举报
回复
要不你都改成 :字段 或者你都改成 ?
如果想 ? :字段 一起使用的话 ?在前面好像可以的,索引从0开始计算
lovezx1028 2010-07-13
  • 打赏
  • 举报
回复

String hql = "FROM WghCustomer AS q where q.customerCode LIKE :? and q.productCode LIKE :?and q.generateFlag LIKE :?and q.weighDate>=? and q.weighDate<=?"; Query q = super.getSession().createQuery(hql); q.setString("customerCode", "%"+customerCode+"%"); q.setString("productCode", "%"+productCode+"%"); q.setString("generateFlag", "%"+generateFlag+"%"); q.setString(0, startDate); q.setString(1, endDate); q.setFirstResult((currentPage - 1) * lineSize); q.setMaxResults(lineSize);


lovezx1028 2010-07-13
  • 打赏
  • 举报
回复

String hql = "FROM WghCustomer AS q where q.customerCode LIKE :customerCode and q.productCode LIKE :? and q.generateFlag LIKE :?and q.weighDate>=? and q.weighDate<=?"; Query q = super.getSession().createQuery(hql); q.setString("customerCode", "%"+customerCode+"%"); q.setString("productCode", "%"+productCode+"%"); q.setString("generateFlag", "%"+generateFlag+"%"); q.setString(0, startDate); q.setString(1, endDate); q.setFirstResult((currentPage - 1) * lineSize); q.setMaxResults(lineSize);


67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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