`
Andrew1945
  • 浏览: 13460 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

hql的烦恼

 
阅读更多
从这开始:
    员工表(Employee):
        字段(简写了):id(int),name(String),sex(boolean),age(int),date(Calendar)...
        注:字段date在数据库中是以yyyy-MM-dd HH:mm:ss这种形式存储的。
现在需要在数据库中取出date字段在当前时间(yyyy-MM-dd HH:mm:ss)之前的所有数据库记录。
1.
hql:"from Employee e where e.date <=" + new Date();

2.
hql:"from Employee e where e.date <=" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

3.
Calendar ca = Calendar.getInstance();
ca.setTime(new Date());
ca.set(Calendar.MILLISECOND, 0);
hql:"from Employee e where e.date <=" + ca;

4.
Calendar ca = Calendar.getInstance();
ca.set(Calendar.MILLISECOND, 0);
Date date = ca.getTime();
hql:"from Employee e where e.date <=" + date;

哪种方法可以正确的查询到数据,或者所有的都不行,希望大家多给点意见,谢谢!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics