public int selectAll(final String time1, final String time2, final int cityname, final String airstatus) { final StringBuffer hql = new StringBuffer( "select count(air) from TableName air where air.cityname=" + cityname + " and air.isDelete=0 and air.strtes1=1 and air.airstatus='" + airstatus + "'"); if (time1 != null && !time1.equals("")) { hql.append(" and air.reportDate >=:time1"); } if (time2 != null && !time2.equals("")) { hql.append(" and air.reportDate <=:time2"); } hql.append(" order by air.cityname asc "); Number list = this.getHibernateTemplate().execute( new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(hql.toString()); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try { if (time1 != null && !time1.equals("")) { query.setDate("time1", df.parse(time1)); } if (time2 != null && !time2.equals("")) { query.setDate("time2", df.parse(time2)); } } catch (ParseException e) { e.printStackTrace(); } return query.uniqueResult(); } }); return list.intValue(); }
详细解决方案
hibernate中的query.uniqueResult()统计回到一个整型数据
热度:601 发布时间:2013-11-16 23:15:33.0
相关解决方案
- hibernate 存入数据库当前时间
- Hibernate 投射文件中length属性无法改变integer字段的默认长度
- Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml解决办法
- hibernate DAO中加了局物,未提交
- hibernate 字段lazy 的兑现原理
- Hibernate 的query.list()的有关问题
- Hibernate 关联表字段赋值有关问题
- 零配置的有关问题(struts2+Hibernate)
- hibernate 连接 oracle session 有关问题
- hibernate 中没有做一对多 , 那种关联映射的关联的话如何做连接查询
- hibernate 联接mysql出错
- 大神们开始觅错啦!org.hibernate.exception.SQLGrammarException: could not execute query
- struts2,hibernate,spring3 常用框架的API CHM版本,该怎么处理
- struts2,hibernate,spring3 惯用框架的API CHM版本
- struts hibernate 测试小例子 不报错 但数据库没反应 求分析项目在小弟我的资源里面
- struts2 hibernate 分页有关问题
- hibernate与此同时使用多数据源?spring+hibernate
- hibernate 保留对象时,根据映射文件,无法获取主键值
- hibernate中Query query=session.createQuery的有关问题
- hibernate 多对多添加有关问题,弄一天多了,请求大佬解答。小的 在此谢过了
- struts + hibernate 后台页面修改数据后,前台页面显示的内容新旧数据交替出现。请高手帮忙分析上原因
- hibernate 多对1关联配置有关问题
- Hibernate,级联保存为何无效?
- hibernate 一对1 ,插入不进去数据
- hibernate 连接oracle异常
- struts+spring+hibernate 开发,在action层调用service层接口,结果替null 注入失败,需高手帮忙
- Hibernate 映射有关问题
- SSH框架导入struts,hibernate,spring分先后顺序吗>>解决方法
- Hibernate 中的session怎么管理
- SSH框架(就是struts+spring+hibernate)是怎么搭建的