java uniqueresult_关于query.uniqueResult报错问题

发布时间:2025-12-09 14:11:00 浏览次数:5

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,但是还是报错。

展开

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477