报错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 )");
}
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'
对应的应该就是这个方法出错,具体该如何处理 —_—||
- 你就没贴过代码
- 为了取总数而查出记录取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()