查询距离当前时间5分钟的数据

查询距离当前时间5分钟的数据

最近在作项目的过程当中,须要用定时任务查询最近一段时间内数据库更新的数据:web

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

TestBean bean=new TestBean();

Date date= new Date();
String startTime=sdf.format(date);                      //系统当前时间
String endTime=sdf.format(date.getTime()-1000*60*5);    //当前时间前五分钟

bean.setStartTime(startTime);
bean.setEndTime(endTime);

//查询距离当前时间五分钟内的数据
list=volcanicDao.selectLog(bean);

//SQL语句:本人用的oracle数据库
select * from TE201 t
where t.update_time between to_date(#{endTime},'yyyy-mm-dd hh24:mi:ss') 
and to_date(#{startTime},'yyyy-mm-dd hh24:mi:ss')
order by t.update_time desc