每天都遇到问题,在使用hql语句进行日期的比较时
比如:传一个Date类型的参数 date
User 对象有一个属性birDate
开始这样写:
select * from User u where u.birDate >= date
结果当然不行,然后这样写 先转成2008-09-09这种日期的str类型
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd:hh12:mm:ss");
String strDate = sdf.format(d);
select * from User u where u.birDate >= to_date(strDate);
还是不行。无语了
再:
select * from User u where u.birDate >= to_date(strDate,'yyyy-mm-dd :hh24:mi:ss');
ok了,如果要放在" "之间,注意字符串拼接 太长了话用StringBuffer