sntatas
2016-05-23 21:00
hql查询两个日期间的记录是下面那样吗?为什么报错
@Test public void secondTest() throws ParseException{ String hql = "select new Map(c.name as name,o.tradedate as tradedate,o.status as status,o.amount as amount) " +"from Customer c,Orderform o " +"where o.tradedate between ? and ? and o.status in('已发货','已付款') and o.price > 1000 " +"order by o.status asc,o.tradedate desc,o.price desc"; Query query = session.createQuery(hql); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date1 = sdf.parse("2015-05-01"); Date date2 = sdf.parse("2015-06-01"); query.setDate(0, date1); query.setDate(1, date2); List<Map> results = query.list(); for(Map r:results){ System.out.println("商品名称:"+r.get("0")); System.out.println("交易日期:"+r.get("1")); System.out.println("交易状态:"+r.get("2")); System.out.println("交易金额:"+r.get("3")); } }
看你的类对不对,我对应的类是Order
下面是错误堆栈
String hql = "select new map(customer.name,tradedate,status,"
+ "amount) from Order where tradedate between "
+ "'2015-5-1' and '2015/6/1' and status in "
+ "('已发货','已付款') and amount > 1000"
+ "order by status asc,tradedate desc,amount desc";
List<Map> maps = session.createQuery(hql).list();
for (Map map : maps)
System.out.println(map.get("0") + " " + map.get("1") + " " + map.get("2") + " " + map.get("3"));
HQL数据查询基础
41151 学习 · 90 问题
相似问题