java uniqueresult_关于query.uniqueResult报错问题

publicfloatcountmonthmoney(Longblogid){java.text.SimpleDateFormatsf=newjava.text.SimpleDateFormat("yyyyMM");Stringtoday=sf.format(newjava.util.Date());StringBuilderstring...

public float countmonthmoney(Long blogid) {

java.text.SimpleDateFormat sf = new java.text.SimpleDateFormat("yyyyMM");

String today = sf.format(new java.util.Date());

StringBuilder stringBuilder = new StringBuilder("select sum(d.emolument) from " + DesignerSelled.REF+ " as d where d." + designerSelled.PROP_DESIGNERID+ "=" + blogid + " and " + "to_char(d."+ DesignerSelled.PROP_SELLEDTIME + ",'yyyyMM')" + "='"+ today + "'");

Session session = null;

float result = 0.0f;

try {

session = this.getSession();

Query query = session.createQuery(stringBuilder.toString());

result = Float.parseFloat((query.uniqueResult()==null?"":query.uniqueResult()).toString());

} finally {closeSession(session);}return result;}

那位高手帮忙看看呀,我这样写是没有错的,但是,每当数据库DesignerSelled表中emolument没有值的时候就会报错 result = Float.parseFloat((query.uniqueResult()==null?"":query.uniqueResult()).toString());就是这句出错严重: Servlet.service() for servlet default threw exception

java.lang.NumberFormatException: empty String

at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)

at java.lang.Float.parseFloat(Float.java:422)

at com.ipingou.shopping.model.dao.impl.DesignerSelledDAOImpl.countmonthmoney(DesignerSelledDAOImpl.java:232)

at com.ipingou.shopping.web.action.member.MemberConsoleAction.toListMyPay(MemberConsoleAction.java:734)

我的字段不为空,我已经给它设为0,但是还是报错。

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
* 查看 */ public List browseMer(int pageSize, int pageNo, int cateId,boolean isSpecial) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; List list = null; try{ String hql = "from Merchandise as a"; if (isSpecial){ hql = hql + " where a.special=1"; }else{ hql = hql + " where a.special=0"; } if (cateId!=0){ hql = hql + " and a.category.id="+cateId; } hql = hql + " order by a.id desc"; Query query = session.createQuery(hql); query.setMaxResults(pageSize); query.setFirstResult((pageNo-1)*pageSize); tx = session.beginTransaction(); list = query.list(); tx.commit(); if (!Hibernate.isInitialized(list))Hibernate.initialize(list); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("MerServiceImpl browseMer异常?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return list; } public List browseMer(int pageSize, int pageNo, String hql) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; List list = null; try{ Query query = session.createQuery(hql); query.setMaxResults(pageSize); query.setFirstResult((pageNo-1)*pageSize); tx = session.beginTransaction(); list = query.list(); tx.commit(); if (!Hibernate.isInitialized(list))Hibernate.initialize(list); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("MerServiceImpl browseMer异常?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return list; } public int countRecord(String hql) throws Exception { Session session = MySessionFactory.getSession(); Transaction tx = null; int count = 0; try{ tx = session.beginTransaction(); Query query = session.createQuery(hql); query.setMaxResults(1); count = ((Integer)query.uniqueResult()).intValue(); tx.commit(); }catch(Exception ex){ if(tx!=null)tx.rollback(); logger.info("MerServiceImpl countRecord异常?\n"); ex.printStackTrace(); }finally{ MySessionFactory.closeSession(); } return count; }
最新发布
05-17

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值