NutzCN Logo
问答 Fail to born 'java.lang.Number'
发布于 3121天前 作者 jozhuzhu 2098 次浏览 复制 上一个帖子 下一个帖子
标签:

报错java.lang.Number
在用sql语句处理我的数据库里面数据的时候,想要通过select count(1) from cdorder 来统计里面查询的数目,但是就报错,不太清楚是要怎么解决。求大神帮忙指导一下。
部分源码如下
if (orderNO.length() <= 0 && orderSource.length() <= 0 && category.length() <= 0
&& brand.length() <= 0 && orderState.length() <= 0)
sb.append("SELECT COUNT(*) FROM CD_ORDER");
if (orderNO.length() > 0)
sb.append("AND ( ORDERNO LIKE @ORDERNO ) ");
if (orderSource.length() > 0)
sb.append("AND ( ORDERSOURCE LIKE @ORDERSOURCE ) ");
if (category.length() > 0)
sb.append("AND ( CATEGORY LIKE @CATEGORY ) ");
if (brand.length() > 0)
sb.append("AND ( BRAND LIKE @BRAND ) ");
if(orderState.length() > 0){
sb.append("AND ( ORDERSTATE LIKE @ORDERSTATE )");
}

10 回复

具体的报错信息呢?报错的语句呢?

Fail to cast from <com.chiefdom.orderManage.vo.OrderVO> to <java.lang.Number> for {com.chiefdom.orderManage.vo.OrderVO@1a13b7de} because:
BorningException:Fail to born 'java.lang.Number'
by args: [
@(com.chiefdom.orderManage.vo.OrderVO@1a13b7de)]
at org.nutz.castor.Castors.cast(Castors.java:264)
at org.nutz.castor.Castors.castTo(Castors.java:318)
at org.nutz.castor.castor.Collection2Object.cast(Collection2Object.java:17)
at org.nutz.castor.castor.Collection2Object.cast(Collection2Object.java:9)
at org.nutz.castor.Castors.cast(Castors.java:252)
at org.nutz.castor.Castors.castTo(Castors.java:318)
at org.nutz.dao.impl.sql.NutStatement.getObject(NutStatement.java:117)
at org.nutz.dao.impl.sql.NutStatement.getNumber(NutStatement.java:164)
at org.nutz.dao.impl.sql.NutStatement.getInt(NutStatement.java:121)
at com.chiefdom.orderManage.dao.OrderDAO.queryOrderList(OrderDAO.java:120)
at com.chiefdom.orderManage.bo.OrderBO.queryOrderList(OrderBO.java:39)
at com.chiefdom.orderManage.action.OrderAction.showOrder(OrderAction.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:51)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
at com.chiefdom.authority.filter.MainNutFilter.doFilter(MainNutFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'java.lang.Number'

在源码中我用了sql.getInt()这个方法,我也是在思考报错语句
Fail to cast from <com.chiefdom.orderManage.vo.OrderVO> to <java.lang.Number> for {com.chiefdom.orderManage.vo.OrderVO@4a2732f3} because:
BorningException:Fail to born 'java.lang.Number'
对应的应该就是这个方法出错,具体该如何处理 —_—||

@wendal
报错的语句出来了,求大神指导一下

@wendal
现在我想到的解决方法是通过sql.getList()把我要的条目都调出来,然后再根据这个List.size()去得到我要的数目,但这是避免报错而已吧

设置的回调不对

取list.size()那叫作死,不叫解决方法。

@wendal
为什么是作死呢?你说的回调不对是指哪方面?

  • 你就没贴过代码
  • 为了取总数而查出记录取size()不是作死是啥?

SQL示例A

Sql sql = Sqls.create("select count(*) from user");
sql.setCallback(Sqls.callback.integer()); // SQL的结果集是一个整型,所以回调选integer()
dao.execute(sql);
int count = sql.getInt();

// 也可以简化为
Sql sql = Sqls.fetchInt(select count(*) from user);
dao.execute(sql);
int count = sql.getInt();

你贴的出错信息里面有这样的提示

<com.chiefdom.orderManage.vo.OrderVO> to <java.lang.Number>

证明Sql存的是OrderVO实例,而非数值, 所以原因就是,要么用了 Sqls.callback.entity() 要么 用的是 Sqls.fetchEntity()

@wendal
多谢你,真的多用了一个Sql.callback.entity(),用了你的方法解决了,也多理解了
其实查出所有相关记录对于我现在做的也是有用的,只是看到之前的代码查了一次所有记录之后就还用了类似的语句查了总数,就想能不能在前一个查了所有记录的基础上,再进行统计。

添加回复
请先登陆
回到顶部