mysql hibernate 时间_跪求:hibernate mysql 查询日期范围(急)

publicListgetTime(DeviceHistorybeTime,DeviceHistoryendTime)throwsException{Listl=newArrayList();Sessions=this.getSession();Queryq=s.createQuery("fromDeviceHistorydwhered....

public List getTime(DeviceHistory beTime,DeviceHistory endTime)throws Exception {

List l=new ArrayList();

Session s = this.getSession();

Query q=s.createQuery("from DeviceHistory d where d.DId=:dd and d.deviceTime between :aa and :bb");

q.setDate("aa", beTime.getDeviceTime());

q.setDate("bb", endTime.getDeviceTime());

l=q.list();

s.close();

return l;

}

public static void main(String[] args) throws Exception{

List l= new ArrayList();

DeviceHistoryDao dgd=new DeviceHistoryDao();

ToChange tc=new ToChange();

DeviceHistory dg=new DeviceHistory();

dg.setDId(1);

// dg.setId(6);

dg.setDeviceTime(tc.charToDate("2008-10-06 13:00"));

DeviceHistory dg1=new DeviceHistory();

dg1.setDId(1);

// dg1.setId(8);

dg1.setDeviceTime(tc.charToDate("2008-10-06 16:00"));

l=dgd.getTime(dg,dg1);

System.out.println("list=="+l.size());

}

public Date charToDate(String s){

DateFormat df=new SimpleDateFormat("yyyy-mm-dd hh:mm");

Date dd=new Date(0);

try {

if(s!=null&&s.trim().length()>0){

dd = (Date) df.parse(s);

}

} catch (Exception e) {

e.printStackTrace();

}

return dd;

}

public class DeviceHistory {

// Fields

private Integer id;

private Integer DId;

private String lng;

private String lat;

private Float speed;

private String info;

private Date deviceTime;

}

真的很不好意思!昨天弄了半天没弄好!再加上晚上已经很晚了哈!所以急了一些!这里向大家道歉!还有你的方法我试了不行!真的很不好意思!

我用这个差寻double范围都好着呢!就唯独date类型查询不出来,得到的list为0;

我这里将我操作的方法,测试的方法,日期类型的转换方法,传递豆里的属性都贴出来了,希望大家能帮我下哈!

我也查了很多的资料可每一个能通过测试取得数据的。

beTime.getDeviceTime()获取的是java.util.Date;类型,在public List getTime(DeviceHistory beTime,DeviceHistory endTime)方法里我少了 q.setInteger("dd", beTime.getDId());这里是我粘贴的时候没有粘上去。对不起哈!如果需要我可以把我的数据也贴上来!

我用的是hibernate没有用其他的框架!还有to_Date我试了在mysql里不行,直接报错的

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值