首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

依据时间Date比较数据库中时间字段获取内容

2012-07-08 
根据时间Date比较数据库中时间字段获取内容String转换DateDateFormat datef new SimpleDateFormat(yyyy

根据时间Date比较数据库中时间字段获取内容
String转换Date

DateFormat datef = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date = datef.parse(cd);


    public Map getSmsContentByCateoryIdOrDate(Long id, Date date) {        Map<String,List> map = new HashMap<String,List>();        final String hq1 = "from SmsContent s where s.category.id="+id+" and s.deleteTime>:expTime";        final String hq2 = "from SmsContent s where s.category.id="+id+" and s.updateTime>:expTime";        final String hq3 = "from SmsContent s where s.category.id="+id+" and s.creationTime>:expTime";        map.put("deletedContentList",getListByName(hq1,date));        map.put("updatedContentList",getListByName(hq2,date));        map.put("addedContentList",getListByName(hq3,date));        map.put("allContentList",null);        return map;    }    //根据参数名返回List    private List getListByName(final String hql,final Date date){        List list = (List)this.getHibernateTemplate().execute(new HibernateCallback() {            public Object doInHibernate(Session session) throws HibernateException, SQLException {            return session.createQuery(hql).setTimestamp("expTime",date).list();            }        });        return list;    }


根据两个时间来获取数据
public List statisticsSmsContentByDate(final Date beginDate,final Date endDate) {       return (List)this.getHibernateTemplate().execute(new HibernateCallback() {            public Object doInHibernate(Session session) throws HibernateException, SQLException {               return session.createCriteria(SmsContent.class).add(Restrictions.ge("creationTime",beginDate))                        .add(Restrictions.lt("creationTime",endDate)).list();                //session.createQuery("ssss :begin :end").setTimestamp().list();            }        });              }

热点排行