java里边能解决  根据时间查询问题吗 ???是这样的  时间为条件   时间格式:yyyy-mm-dd hh:mm:ss  我查询出来的数据是错误的 
哪位大侠帮帮忙 解决一下  谢谢了 

解决方案 »

  1.   

    public List<Object> displaySlotStatus(String wareHourse, String startDate,
    String endDate, int firstPage, int pageSize) {
    String sql = "from WmsStockSlot as wss where wss.stockImportDate >= ? and wss.stockImportDate<=? and wss.id.stockWarehouseId = ?";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date d1 = null;
    Date d2 = null;
    try {
    if (startDate.length() == 10) {
    d1 = sdf.parse(startDate + " 00:00:00");
    d2 = sdf.parse(endDate + " 23:59:59");
    } else {
    d1 = sdf.parse(startDate);
    d2 = sdf.parse(endDate);
    }
    } catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    java.sql.Timestamp sqlD1 = new java.sql.Timestamp(d1.getTime());
    java.sql.Timestamp sqlD2 = new java.sql.Timestamp(d2.getTime());
    try {
    Query query = this.getSession().createQuery(sql);
    query.setTimestamp(0, sqlD1);
    query.setTimestamp(1, sqlD2);
    query.setString(2, wareHourse);
    query.setFirstResult(firstPage);
    query.setMaxResults(pageSize);
    return query.list();
    } catch (RuntimeException e) {
    throw e;
    } finally {
    this.getSession().close();
    }
    }参考参考,看能不能解决你的问题
      

  2.   

    要么是date,要么是timestamp呀,不过你可以转成char或者string
      

  3.   

    java.sql.Timestamp sqlD1 = new java.sql.Timestamp(d1.getTime()); 
    java.sql.Timestamp sqlD2 = new java.sql.Timestamp(d2.getTime()); 
    try { 
    Query query = this.getSession().createQuery(sql); 
    query.setTimestamp(0, sqlD1); 
    query.setTimestamp(1, sqlD2); 
     hibernate这里是timestamp类型的   那导数据路里边应该是什么类型的呢?    “要么是date,要么是timestamp呀 ”  两种类型都可以吗?????
      

  4.   

    date就是只有日期部分,timestamp是日期和时间都有
      

  5.   


    oracle数据库   
      

  6.   

    java.sql.Timestamp sqlD1 = new java.sql.Timestamp(d1.getTime()); 
    java.sql.Timestamp sqlD2 = new java.sql.Timestamp(d2.getTime()); 
    try { 
    Query query = this.getSession().createQuery(sql); 
    query.setTimestamp(0, sqlD1); 
    query.setTimestamp(1, sqlD2); 
    这种形式我试了   不行查出来的数据不正确