原先有套系统是基于sql server 2000开发的,其中对时间段的HQL查询操作如下:
在sql server下执行没有任何问题,但映射到oracle 10g数据库上时就会报错,就是因为参数格式不正确!
在映射文件中,时间字段的映射如下:
[quote]
<property name="optdate" type="java.util.Date">
<column name="OPTDATE" not-null="true"></column>
</property>
[/quote]
明确时间格式为“YYYY-MM-DD HH24:MI:SS"后,需要修改HQL语句如下:
测试通过!
DateFormat dateFormat = DateFormat.getDateTimeInstance();
String queryString = "select u from UserAudit u where u.optuser like '"+username+"' and u.optdate >= '"+dateFormat.format(starttime)+"' and u.optdate < '"+dateFormat.format(endtime)+"'";
在sql server下执行没有任何问题,但映射到oracle 10g数据库上时就会报错,就是因为参数格式不正确!
在映射文件中,时间字段的映射如下:
[quote]
<property name="optdate" type="java.util.Date">
<column name="OPTDATE" not-null="true"></column>
</property>
[/quote]
明确时间格式为“YYYY-MM-DD HH24:MI:SS"后,需要修改HQL语句如下:
select u from UserAudit u where u.optuser like '"+username+"' and u.optdate >= to_date('"+dateFormat.format(starttime)+"','YYYY-MM-DD HH24:MI:SS') and u.optdate < to_date('"+dateFormat.format(endtime)+"','YYYY-MM-DD HH24:MI:SS')"
测试通过!