1.
Date date=Calendar.getInstance().getTime(); Date date1=Calendar.getInstance().getTime(); String hql ="From Student s where 1=1 " +" and s.time != null " +" and s.time >:date " +" and s.time <=:date1 "; Query query=sessionFactory.createQuery(hql); query.setTimestamp("date", date);//注意这里,用setTimestampe,不要用setDate query.setTimestamp("date1", date1); List<Student> list=query.list();
2.
java.util.Date date=new java.util.Date(); String hql="select i from table i where to_char(i.date,'yyyy-MM-dd') = to_char(?,yyyy-MM-dd)"; Query q=new Query(hql); q.setDate(0,date);
3.
java.util.Date date=new java.util.Date(); String hql="select i from table i where i.date=?"; Query q=new Query(hql); q.setDate(0,date);