HQL查询问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 07:38:12
session =HibernateSessionFactory.getSession();
ts =session.beginTransaction();
Query query =session.createQuery("select sum(traBalance) from TradesRecod where teaId ="+tea_id+" and traTime='"+year+"-"+month+"-01'");
上面语句可以查询,没有问题,例如写个main测试中为2008-07-01号sum(traBalance),现在改成查询一段日期报错.修改如下
session =HibernateSessionFactory.getSession();
ts =session.beginTransaction();
Query query =session.createQuery("select sum(traBalance) from TradesRecod where teaId ="+tea_id+" between traTime='"+year+"-"+month+"-01' and traTime='"+year+"-"+month+"-31'");
-----------------------------------------------------------
现在出异常,Caused by: line 1:91: expecting "and", found '='
-----------------------------------------------------------
语句怎么改合适?date我想用between and查询一段日期.

between traTime='"+year+"-"+month+"-01' and traTime='"+year+"-"+month+"-31'");
应该是 traTime between 2008-1-1 and 2008-2-2 类似这样的语法

Query query =session.createQuery("select sum(traBalance) from TradesRecod where teaId =:"+tea_id+" and traTime=:'"+year+"-"+month+"-01'"); 试试 这样可以吧???