错误语句:
SELECT IFNULL(MAX(xzqhbh)+1,CONCAT('100','01')) as a FROM xzqh WHERE fjxzqhbh ='#' 表结构和数据。
CREATE TABLE `xzqh` ( `ID` bigint(20) NOT NULL auto_increment, `XZQHBH` varchar(255) default NULL COMMENT '行政区划编号', `FJXZQHBH` varchar(255) default NULL COMMENT '父级行政区划编号', `XZQHMC` varchar(255) NOT NULL COMMENT '行政区划名称', `XZQHDM` varchar(10) NOT NULL COMMENT '行政区划代码', `XZQHJB` tinyint(4) default NULL COMMENT '0总局 1省 2市 3县 4乡镇 5村', `XZQHMS` varchar(255) default NULL COMMENT '行政区划描述', `XZQHPX` int(10) default NULL COMMENT 'jsTree所用到的属性(默认为空)', PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=259 DEFAULT CHARSET=utf8 COMMENT='行政区划表'; /*Data for the table `xzqh` */ insert into `xzqh`(`ID`,`XZQHBH`,`FJXZQHBH`,`XZQHMC`,`XZQHDM`,`XZQHJB`,`XZQHMS`,`XZQHPX`) values (1,'-1','#','中国','000000',0,NULL,7); 贴上异常: java.lang.ClassCastException: [B cannot be cast to com.jfinal.plugin.activerecord.Record at com.askj.zs.xzqh.model.Xzqh.addByPar(Xzqh.java:82) at com.askj.zs.xzqh.controller.XzqhController.xzqhTreeSave(XzqhController.java:73) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.jfinal.aop.Invocation.invoke(Invocation.java:73) at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:47) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) 出错误处的源码:
<T> List<T> query(Config config, Connection conn, String sql, Object... paras) throws SQLException { ArrayList result = new ArrayList(); PreparedStatement pst = conn.prepareStatement(sql); config.dialect.fillStatement(pst, paras); ResultSet rs = pst.executeQuery(); int colAmount = rs.getMetaData().getColumnCount(); if(colAmount <= 1) { if(colAmount == 1) { while(rs.next()) { result.add(rs.getObject(1)); } } } else { while(rs.next()) { Object[] temp = new Object[colAmount]; for(int i = 0; i < colAmount; ++i) { temp[i] = rs.getObject(i + 1); } result.add(temp); } } DbKit.close(rs, pst); return result; }
result.add(rs.getObject(1)); result里面的值就已经错了。以为是JDBC的问题,但是我自己写JDBC查询方法,是没问题的。