作者你好,今天用了下导入功能,然后报错,能帮忙看一下什么问题吗,代码和报错如下
,如下是根据jfinal-layui的导入改的我自己的导入方法,业务上是没有问题的,但是每次都报关于数据库的错
public boolean importExcelhouse(UploadFile uf, String sql) { UploadFile up = uf; List<Object[]> list = ExcelKit.getExcelData(up.getFile()); List<Object[]> addList = new ArrayList<>();//实际需要新增的记录 Object[][] objs=new Object[list.size()][list.get(0).length+1]; List<Map<String,Object>> datalist = new ArrayList<>(); for(int i=0;i<list.size();i++){ //如果当前行已经在数据库中存在,则跳过 Record xiaoqu = Db.findFirst("select * from w_tb_xiaoqu_danyuan where name = ? and isDel ='0'",list.get(i)[0]); if (xiaoqu == null){ LOG.info(list.get(i)[0]+"小区不存在"); return false; } Record loudong = Db.findFirst("select * from w_tb_xiaoqu_danyuan where name = ? and pid =? and isDel ='0'",list.get(i)[1],xiaoqu.get("id")); if (loudong == null){ LOG.info(list.get(i)[1]+"楼栋不存在"); return false; } Record danyuan = Db.findFirst("select * from w_tb_xiaoqu_danyuan where name = ? and pid =? and isDel ='0'",list.get(i)[2],loudong.get("id")); if (danyuan == null){ LOG.info(list.get(i)[1]+"单元不存在"); return false; } //查询房屋信息在数据库中是否已存在,若存在则跳过 Record fangwu = Db.findFirst("select * from w_tb_house where xiaoquId = ? and loudongId=? and danyuanId=? and houseNum=? and isDel ='0'", list.get(i)[0],list.get(i)[1],list.get(i)[2],list.get(i)[3]); if (fangwu != null){ continue; } //判断该房屋信息在list中是否已存在 boolean exist = false; for (int i1 = 0; i1 < addList.size(); i1++) { if (addList.get(i1)[0].equals(list.get(i)[0]) && addList.get(i1)[1].equals(list.get(i)[1]) && addList.get(i1)[2].equals(list.get(i)[2]) && addList.get(i1)[3].equals(list.get(i)[3])){ exist=true; break; } } if (exist){ continue; } addList.add(list.get(i)); } Object[][] addobjs=new Object[addList.size()][addList.get(0).length+1]; for (int i = 0; i < addList.size(); i++) { //如果当前行已经在数据库中存在,则跳过 Record xiaoqu = Db.findFirst("select * from w_tb_xiaoqu_danyuan where name = ? and isDel ='0'",addList.get(i)[0]); Record loudong = Db.findFirst("select * from w_tb_xiaoqu_danyuan where name = ? and pid =? and isDel ='0'",addList.get(i)[1],xiaoqu.get("id")); Record danyuan = Db.findFirst("select * from w_tb_xiaoqu_danyuan where name = ? and pid =? and isDel ='0'",addList.get(i)[2],loudong.get("id")); for(int j=0;j<addList.get(0).length;j++){//遍历列 if(j==0){//小区名称 addobjs[i][0]= IdKit.createUUID(); addobjs[i][1]=xiaoqu.get("id"); }else if(j==1){//小区楼栋 addobjs[i][2]=loudong.get("id"); }else if(j==2){//单元 addobjs[i][3]=danyuan.get("id"); }else{ addobjs[i][j+1]=addList.get(i)[j]; } } } return Db.tx(new IAtom() { boolean save_flag = true; @Override public boolean run() throws SQLException { try { //批量导入 Db.batch(sql, addobjs, 100); } catch (Exception e) { save_flag = false; e.printStackTrace(); } return save_flag; } }); }
报错日志如下
2021-10-08 12:13:20 [Thread: XNIO-1 task-1]-[ERROR]-[com.alibaba.druid.pool.DruidDataSource.handleFatalError()]: discard connection com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 21 milliseconds ago. The last packet sent successfully to the server was 19 milliseconds ago. at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:172) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:960) at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1019) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:3240) at com.alibaba.druid.filter.FilterAdapter.preparedStatement_executeQuery(FilterAdapter.java:1087) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:3237) at com.alibaba.druid.wall.WallFilter.preparedStatement_executeQuery(WallFilter.java:648) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:3237) at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeQuery(FilterEventAdapter.java:465) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:3237) at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.executeQuery(PreparedStatementProxyImpl.java:181) at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:227) at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:384) at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:398) at com.jfinal.plugin.activerecord.DbPro.findFirst(DbPro.java:426) at com.jfinal.plugin.activerecord.Db.findFirst(Db.java:314) at com.qinhailin.common.base.service.FileService.importExcelhouse(FileService.java:403) at com.qinhailin.common.base.BaseController.importExcelhouse(BaseController.java:302) at com.qinhailin.portal.business.ctrl.TbHouseController.daoru(TbHouseController.java:102) 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:498) at com.jfinal.aop.Invocation.invoke(Invocation.java:97) at com.jfinal.plugin.activerecord.tx.TxByMethods.intercept(TxByMethods.java:57) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.jfinal.plugin.activerecord.tx.TxByMethodRegex.intercept(TxByMethodRegex.java:61) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.qinhailin.common.intercepor.LoggerInterceptor.intercept(LoggerInterceptor.java:49) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.qinhailin.common.intercepor.TokenInterceptor.intercept(TokenInterceptor.java:61) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.qinhailin.common.intercepor.ExceptionInterceptor.intercept(ExceptionInterceptor.java:44) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.qinhailin.common.intercepor.SessionInterceptor.intercept(SessionInterceptor.java:133) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:96) at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:46) at com.qinhailin.common.safe.XssHandler.handle(XssHandler.java:55) at com.qinhailin.common.handler.CommonHandler.handle(CommonHandler.java:77) at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:81) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:90) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure The last packet successfully received from the server was 21 milliseconds ago. The last packet sent successfully to the server was 19 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:103) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:149) at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:165) at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:563) at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:735) at com.mysql.cj.protocol.a.NativeProtocol.sendCommand(NativeProtocol.java:674) at com.mysql.cj.protocol.a.NativeProtocol.sendQueryPacket(NativeProtocol.java:966) at com.mysql.cj.NativeSession.execSQL(NativeSession.java:1165) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:937) ... 74 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at com.mysql.cj.protocol.ReadAheadInputStream.fill(ReadAheadInputStream.java:107) at com.mysql.cj.protocol.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:150) at com.mysql.cj.protocol.ReadAheadInputStream.read(ReadAheadInputStream.java:180) at java.io.FilterInputStream.read(FilterInputStream.java:133) at com.mysql.cj.protocol.FullReadInputStream.readFully(FullReadInputStream.java:64) at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:63) at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:45) at com.mysql.cj.protocol.a.TimeTrackingPacketReader.readHeader(TimeTrackingPacketReader.java:52) at com.mysql.cj.protocol.a.TimeTrackingPacketReader.readHeader(TimeTrackingPacketReader.java:41) at com.mysql.cj.protocol.a.MultiPacketReader.readHeader(MultiPacketReader.java:54) at com.mysql.cj.protocol.a.MultiPacketReader.readHeader(MultiPacketReader.java:44) at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:557) ... 79 more
麻烦作者帮忙看一下到底是什么原因,不胜感激
项目:
JFinal-layui