小弟最近在项目中遇到了这个问题,在oracle数据库里,想查2010-4月份的数据,可以使用:
select * from day_report where to_char('curdate','yyyy-MM') = '2010-04'
这样的方式查询到。
那么在hibernate里,要使用criteria来查询应该怎么查?问题是我不知道如何从date型数据里,查询指定月份和年份,哪位大哥能给的大概的方法~~~ 

解决方案 »

  1.   

    使用between,参考下面:      //Criteria Query Example
          Criteria crit = 
    session.createCriteria(Insurance.class);
          DateFormat format = 
    new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
          Date startDate = 
    (Date)format.parse("2010-04-01 00:00:00");
          Date endDate = 
    (Date)format.parse("2010-05-01 00:00:00");
          crit.add(Expression.between
    ("investementDate", new Date(startDate.getTime()),
     new Date(endDate.getTime()))); //