hibernate HQL中的日期类型的查询

来源:百度知道 编辑:UC知道 时间:2024/05/14 02:05:17
数据库oracle,表table
String name = aaa;
Date begintime;
Date endtime;

String hql = "from table t where 1=1 ";
wherehql = "";
if(name!=null && !name.equals("")){
wherehql+ = "and t.name like '%" + name + "%'";
}else if(begintime!=null||endtime!=null && !begintime.equals("")||endtime.equals("")){
wherehql+ = "and t.begintime >什么 and t.endtime < 什么";
}
getHibernateTemplate().find(hql+wherehql, null);

上面这个日期类型的值是怎么传进去啊。。。。。。
帮忙回答一下谢谢!!!!!

你可以试试看用new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(begintime); 转换为String
然后用oracle本身的函数to_date("2008-11-11 11:11:11", "yyyy-MM-dd HH24:mi:ss");

String formatbgString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(begintime);
String formatendString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(begintime);

"and t.begintime > to_date('" + formatbgString + "', 'yyyy-MM-dd HH24:mi:ss') and t.endtime < to_date('" + formatendString + "', 'yyyy-MM-dd HH24:mi:ss')"

DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String begin=df.format(begintime);
String end=df.format(endtime);

wherehql+ = "and t.begintime >"+begin+" and t.endtime < "+end;

DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String begin=df.format(begin