Hibernate不同DB的日期查询

Java web项目开发,ORM层用的是Hibernate,用HQL语句查询不同数据库时,日期时间比较还是有所区别的。

1、在Mysql数据库时,是这样写的:

上面是个代码拼串截图,翻译一下是这样的:

from MyObj where t.addTime >='2016-06-01' and  t.addTime <= '2016-06-10 23:59:59'

 

2、在Oracle数据库中,是这样写的:

翻译一下:

from MyObj where   t.addTime >= to_date('2016-06-01' , 'YYYY-MM-DD') 

and t.addTime <= to_date( '2016-06-10 23:59:59','YYYY-MM-DD HH24:MI:SS')

 

3、java代码中日期格式化是这样的,备记。

Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);

 

posted @ 2016-06-18 21:45  月下麦田  阅读(501)  评论(0编辑  收藏  举报