NutzCN Logo
问答 执行入口方法却提示:“与服务器的连接已被中止”
发布于 2844天前 作者 qq_ff330a3f 2060 次浏览 复制 上一个帖子 下一个帖子
标签:

想问下兽总,为何我在执行某个入口方法的时候第一次手动执行可以执行成功,但是当我再次手动执行同一个方法之后却提示“CaseMessage=与服务器的连接已被中止。”这个错误呢?

21 回复

贴日志和代码

日志:

DEBUG] 2017-03-10 04:58:36 (UrlMappingImpl.java:get:101)
Found mapping for [GET] path=/rain/testMethod : RainModule.testMethod(RainModule.java:236)
DEBUG] 2017-03-10 04:58:36 (NutIoc.java:get:151)
Get 'rainModule'<class com.beyondb.rainsnow.modules.RainModule>
DEBUG] 2017-03-10 04:58:36 (NutDaoExecutor.java:printSQL:388)
SELECT * FROM stationdetail 
DEBUG] 2017-03-10 04:58:36 (NutDaoExecutor.java:exec:97)
SQLException
java.sql.SQLNonTransientConnectionException: 与服务器的连接已被中止。
	at com.beyondb.gcf.util.SqlExType.getSqlEx(SqlExType.java:97)
	at com.beyondb.gcf.util.SqlExFactory.get(SqlExFactory.java:96)
	at com.beyondb.gcf.jdbc.DrvObj.readError(DrvObj.java:852)
	at com.beyondb.gcf.jdbc.JdbcStmt.readError(JdbcStmt.java:2814)
	at com.beyondb.gcf.jdbc.DrvObj.readResults(DrvObj.java:636)
	at com.beyondb.gcf.jdbc.JdbcStmt.readResults(JdbcStmt.java:2711)
	at com.beyondb.gcf.jdbc.JdbcStmt.readResults(JdbcStmt.java:2662)
	at com.beyondb.gcf.jdbc.JdbcStmt.exec(JdbcStmt.java:1569)
	at com.beyondb.gcf.jdbc.JdbcStmt.executeQuery(JdbcStmt.java:472)
	at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
	at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:246)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:114)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:70)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:247)
	at org.nutz.dao.impl.NutDao.query(NutDao.java:464)
	at org.nutz.dao.impl.NutDao.query(NutDao.java:469)
	at com.beyondb.rainsnow.services.RainSnowStatisticsJobService.generateRainData(RainSnowStatisticsJobService.java:50)
	at com.beyondb.rainsnow.modules.RainModule.testMethod(RainModule.java:236)
	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:497)
	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:126)
	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:198)
	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:217)
	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:142)
	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:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
	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)
 WARN] 2017-03-10 04:58:36 (FailProcessor.java:process:28)
Error@/rain/testMethod :
org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT * FROM stationdetail '
PreparedStatement: 
'SELECT * FROM stationdetail '
CaseMessage=与服务器的连接已被中止。
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:147)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:114)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:70)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:247)
	at org.nutz.dao.impl.NutDao.query(NutDao.java:464)
	at org.nutz.dao.impl.NutDao.query(NutDao.java:469)
	at com.beyondb.rainsnow.services.RainSnowStatisticsJobService.generateRainData(RainSnowStatisticsJobService.java:50)
	at com.beyondb.rainsnow.modules.RainModule.testMethod(RainModule.java:236)
	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:497)
	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:126)
	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:198)
	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:217)
	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:142)
	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:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
	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: java.sql.SQLNonTransientConnectionException: 与服务器的连接已被中止。
	at com.beyondb.gcf.util.SqlExType.getSqlEx(SqlExType.java:97)
	at com.beyondb.gcf.util.SqlExFactory.get(SqlExFactory.java:96)
	at com.beyondb.gcf.jdbc.DrvObj.readError(DrvObj.java:852)
	at com.beyondb.gcf.jdbc.JdbcStmt.readError(JdbcStmt.java:2814)
	at com.beyondb.gcf.jdbc.DrvObj.readResults(DrvObj.java:636)
	at com.beyondb.gcf.jdbc.JdbcStmt.readResults(JdbcStmt.java:2711)
	at com.beyondb.gcf.jdbc.JdbcStmt.readResults(JdbcStmt.java:2662)
	at com.beyondb.gcf.jdbc.JdbcStmt.exec(JdbcStmt.java:1569)
	at com.beyondb.gcf.jdbc.JdbcStmt.executeQuery(JdbcStmt.java:472)
	at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
	at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:246)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	... 62 more

代码:

public boolean generateRainData(){
        boolean flag = false;
        //查询所有站点,并且拼接集合
        List<Stationdetail> stationList = this.dao().query(Stationdetail.class, null);
        //站名以及站点对应集合
        Map<BigInteger,Stationdetail> stationMap = new HashMap<BigInteger,Stationdetail>();
        for(Stationdetail station : stationList){
            stationMap.put(station.getSno(), station);
        }
        
        //先查询一下这三张表是否有数据,如果有的话做更新操作,没有的话进行数据插入操作
        String nowDate = TimeUtil.dateToString(new Date()).split(" ")[0];//格式为yyyy-MM-dd
        String nowMonthDate = nowDate.substring(0, nowDate.lastIndexOf("-"));//格式为yyyy-MM
        String nowYearDate = nowDate.split("-")[0];//格式为yyyy
        String firstMonthDate = getFirstDay();//当月的第一天
        String lastMonthDate = getLastDay();//当月的最后一天
        
        //查询当日雨量数据条数
        int dayDataCount = this.dao().count("hy_rain_d", Cnd.where("checktime", "=", nowDate));
        int index_dayCount = this.dao().count("hy_rain_d",null);
        //查询当月雨量数据条数
        int monthDataCount = this.dao().count("hy_rain_m", Cnd.where("checktime", "=", nowMonthDate));
        int index_monthCount = this.dao().count("hy_rain_m",null);
        //查询当年雨量数据条数
        int yearDataCount = this.dao().count("hy_rain_y", Cnd.where("checktime", "=", nowYearDate));
        int index_yearCount = this.dao().count("hy_rain_y",null);
        
        //获取昨日八点的具体日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();  
        c.add(Calendar.DATE, - 1);  
        Date date = c.getTime();
        String beginTime = sdf.format(date)+" 08:00:00";
        //获取当前日期时间加一小时具体日期
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c1 = Calendar.getInstance();  
        c1.add(Calendar.HOUR_OF_DAY, 0);  
        Date date1 = c1.getTime();
        String endTime = sdf1.format(date1)+" 08:00:00";

        //调用方法返回数据
        List<Record> list = rainOpService.getStationRainPv(beginTime, endTime);
        //调用方法返回月雨量数据
        List<Record> monthList = getPvListData(getRainSnowPvListData(firstMonthDate,lastMonthDate,"hy_rain_d"),stationMap);
        //调用方法返回年雨量数据
        List<Record> yearList = getPvListData(getRainSnowPvListData(nowDate.split("-")[0]+"-01",nowDate.split("-")[0]+"-12","hy_rain_m"),stationMap);
        if(dayDataCount<=0){//如果没有数据则添加一条数据
            //获取所有站点当天的雨量情况
            List<Record> rainPvDataList = getPvListData(list,stationMap);
            //进行批量插入操作
            Sql addBatchSql = Sqls.create("insert into hy_rain_d (dataid,checktime,sno,rainfall) values(@dataid,@checktime,@sno,@rainfall)");
            for (Record record:rainPvDataList) {
                index_dayCount++;
                addBatchSql.params().set("dataid",new BigInteger(record.getString("sno")+index_dayCount)).set("checktime", nowDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                addBatchSql.addBatch();
            }
            //如果数据量多的话可以约定好多少次进行一次批量操作
            this.dao().execute(addBatchSql);
            flag = true;
        }else{//存在数据就进行更新
            //获取所有站点当天的雨量情况
            List<Record> rainPvDataList = getPvListData(list,stationMap);
            //进行批量插入操作
            Sql updateBatchSql = Sqls.create("update hy_rain_d set rainfall=@rainfall where checktime=@checktime and sno=@sno");
            for (Record record:rainPvDataList) {
                updateBatchSql.params().set("checktime", nowDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                updateBatchSql.addBatch();
            }
            //如果数据量多的话可以约定好多少次进行一次批量操作
            this.dao().execute(updateBatchSql);
            flag = true;
        }
        if(monthDataCount<=0){//插入月数据
            Sql addBatchSql = Sqls.create("insert into hy_rain_m (dataid,checktime,sno,rainfall) values(@dataid,@checktime,@sno,@rainfall)");
            //把查询月的方法提出去
            for(Record record:monthList){
                index_monthCount++;
                addBatchSql.params().set("dataid",new BigInteger(record.getString("sno")+index_monthCount)).set("checktime", nowMonthDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                addBatchSql.addBatch();
            }
            this.dao().execute(addBatchSql);
            flag = true;
        }else{//更新月数据
            Sql updateBatchSql = Sqls.create("update hy_rain_m set rainfall=@rainfall where checktime=@checktime and sno=@sno");
            for(Record record:monthList){
                updateBatchSql.params().set("checktime", nowMonthDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                updateBatchSql.addBatch();
            }
            this.dao().execute(updateBatchSql);
            flag = true;
        }
        if(yearDataCount<=0){//插入年数据
            Sql addBatchSql = Sqls.create("insert into hy_rain_y (dataid,checktime,sno,rainfall) values(@dataid,@checktime,@sno,@rainfall)");
            //把查询月的方法提出去
            for(Record record:yearList){
                index_yearCount++;
                addBatchSql.params().set("dataid",new BigInteger(record.getString("sno")+index_yearCount)).set("checktime",nowYearDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                addBatchSql.addBatch();
            }
            this.dao().execute(addBatchSql);
            flag = true;
        }else{//更新年数据
            Sql updateBatchSql = Sqls.create("update hy_rain_y set rainfall=@rainfall where checktime=@checktime and sno=@sno");
            for(Record record:yearList){
                updateBatchSql.params().set("checktime", nowYearDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                updateBatchSql.addBatch();
            }
            this.dao().execute(updateBatchSql);
            flag = true;
        }
        return flag;
    }
public boolean generateRainData(){
        boolean flag = false;
        //查询所有站点,并且拼接集合
        List<Stationdetail> stationList = this.dao().query(Stationdetail.class, null);
        //站名以及站点对应集合
        Map<BigInteger,Stationdetail> stationMap = new HashMap<BigInteger,Stationdetail>();
        for(Stationdetail station : stationList){
            stationMap.put(station.getSno(), station);
        }
        
        //先查询一下这三张表是否有数据,如果有的话做更新操作,没有的话进行数据插入操作
        String nowDate = TimeUtil.dateToString(new Date()).split(" ")[0];//格式为yyyy-MM-dd
        String nowMonthDate = nowDate.substring(0, nowDate.lastIndexOf("-"));//格式为yyyy-MM
        String nowYearDate = nowDate.split("-")[0];//格式为yyyy
        String firstMonthDate = getFirstDay();//当月的第一天
        String lastMonthDate = getLastDay();//当月的最后一天
        
        //查询当日雨量数据条数
        int dayDataCount = this.dao().count("hy_rain_d", Cnd.where("checktime", "=", nowDate));
        int index_dayCount = this.dao().count("hy_rain_d",null);
        //查询当月雨量数据条数
        int monthDataCount = this.dao().count("hy_rain_m", Cnd.where("checktime", "=", nowMonthDate));
        int index_monthCount = this.dao().count("hy_rain_m",null);
        //查询当年雨量数据条数
        int yearDataCount = this.dao().count("hy_rain_y", Cnd.where("checktime", "=", nowYearDate));
        int index_yearCount = this.dao().count("hy_rain_y",null);
        
        //获取昨日八点的具体日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();  
        c.add(Calendar.DATE, - 1);  
        Date date = c.getTime();
        String beginTime = sdf.format(date)+" 08:00:00";
        //获取当前日期时间加一小时具体日期
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c1 = Calendar.getInstance();  
        c1.add(Calendar.HOUR_OF_DAY, 0);  
        Date date1 = c1.getTime();
        String endTime = sdf1.format(date1)+" 08:00:00";

        //调用方法返回数据
        List<Record> list = rainOpService.getStationRainPv(beginTime, endTime);
        //调用方法返回月雨量数据
        List<Record> monthList = getPvListData(getRainSnowPvListData(firstMonthDate,lastMonthDate,"hy_rain_d"),stationMap);
        //调用方法返回年雨量数据
        List<Record> yearList = getPvListData(getRainSnowPvListData(nowDate.split("-")[0]+"-01",nowDate.split("-")[0]+"-12","hy_rain_m"),stationMap);
        if(dayDataCount<=0){//如果没有数据则添加一条数据
            //获取所有站点当天的雨量情况
            List<Record> rainPvDataList = getPvListData(list,stationMap);
            //进行批量插入操作
            Sql addBatchSql = Sqls.create("insert into hy_rain_d (dataid,checktime,sno,rainfall) values(@dataid,@checktime,@sno,@rainfall)");
            for (Record record:rainPvDataList) {
                index_dayCount++;
                addBatchSql.params().set("dataid",new BigInteger(record.getString("sno")+index_dayCount)).set("checktime", nowDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                addBatchSql.addBatch();
            }
            //如果数据量多的话可以约定好多少次进行一次批量操作
            this.dao().execute(addBatchSql);
            flag = true;
        }else{//存在数据就进行更新
            //获取所有站点当天的雨量情况
            List<Record> rainPvDataList = getPvListData(list,stationMap);
            //进行批量插入操作
            Sql updateBatchSql = Sqls.create("update hy_rain_d set rainfall=@rainfall where checktime=@checktime and sno=@sno");
            for (Record record:rainPvDataList) {
                updateBatchSql.params().set("checktime", nowDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                updateBatchSql.addBatch();
            }
            //如果数据量多的话可以约定好多少次进行一次批量操作
            this.dao().execute(updateBatchSql);
            flag = true;
        }
        if(monthDataCount<=0){//插入月数据
            Sql addBatchSql = Sqls.create("insert into hy_rain_m (dataid,checktime,sno,rainfall) values(@dataid,@checktime,@sno,@rainfall)");
            //把查询月的方法提出去
            for(Record record:monthList){
                index_monthCount++;
                addBatchSql.params().set("dataid",new BigInteger(record.getString("sno")+index_monthCount)).set("checktime", nowMonthDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                addBatchSql.addBatch();
            }
            this.dao().execute(addBatchSql);
            flag = true;
        }else{//更新月数据
            Sql updateBatchSql = Sqls.create("update hy_rain_m set rainfall=@rainfall where checktime=@checktime and sno=@sno");
            for(Record record:monthList){
                updateBatchSql.params().set("checktime", nowMonthDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                updateBatchSql.addBatch();
            }
            this.dao().execute(updateBatchSql);
            flag = true;
        }
        if(yearDataCount<=0){//插入年数据
            Sql addBatchSql = Sqls.create("insert into hy_rain_y (dataid,checktime,sno,rainfall) values(@dataid,@checktime,@sno,@rainfall)");
            //把查询月的方法提出去
            for(Record record:yearList){
                index_yearCount++;
                addBatchSql.params().set("dataid",new BigInteger(record.getString("sno")+index_yearCount)).set("checktime",nowYearDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                addBatchSql.addBatch();
            }
            this.dao().execute(addBatchSql);
            flag = true;
        }else{//更新年数据
            Sql updateBatchSql = Sqls.create("update hy_rain_y set rainfall=@rainfall where checktime=@checktime and sno=@sno");
            for(Record record:yearList){
                updateBatchSql.params().set("checktime", nowYearDate).set("sno", new BigInteger(record.getString("sno"))).set("rainfall", Double.parseDouble(record.getString("pv")));
                updateBatchSql.addBatch();
            }
            this.dao().execute(updateBatchSql);
            flag = true;
        }
        return flag;
    }

是不是这数据库不支持连接池?

有可能吧,我用的数据库是我们公司自己的数据库,那该怎么办呢?兽总?

@wendal 我的dao.js配置如下:


var ds = { dataSource: { type: "org.apache.commons.dbcp.BasicDataSource", events: { depose: 'close' }, fields: { // 请修改下面的数据库连接信息 url: 'jdbc:beyondb://192.168.1.55:II7/shuiwen;auto=multi;TZ=HONG-KONG', driverClassName: 'com.beyondb.jdbc.BeyondbDriver', username: 'shuiwen', password: '123456', maxActive: 5, testWhileIdle: true, testOnBorrow: false, testOnReturn: false } }, dao: { type: 'org.nutz.dao.impl.NutDao', args: [{ refer: 'dataSource' }] } };

换成SimpleDataSource类,这个不带连接池功能.

另外可以问一下你们公司的其他技术人员,确认一下是否支持连接池

@wendal 兽总,敢问这个类是哪个包的啊。。。

eclipse? ctrl+shift+t 然后输类名

@wendal 别的配置应该就不用修改了吧?

要改,对着那个类的属性改,没有对应的就得删掉

@wendal 是org.nutz.dao.impl.SimpleDataSource这个类吗?有木有示例啊,兽总,救命啊。。。。

@wendal 谢谢兽总,但是这个类里面并没有支持我们公司自己的数据库驱动,请问还有别的方法吗?真的是连接不够导致的吗?我是不是只能手动写一个连接池了呢?

首先,我没说连接不够用,我说的是 数据库是不是不支持连接池

然后,SimpleDataSource没加载你们的驱动?简单啦,继承它,在构造方法里面.Class.forName加载一下

@wendal 嗯,好的,知道了,兽总,谢谢兽总

@wendal 兽总,我是这么写的,但是在程序运行的还是还是提醒我没有找到驱动类。代码如下:

public class DataSource extends SimpleDataSource{
    public DataSource() throws ClassNotFoundException, InstantiationException, IllegalAccessException{
        Class<?> clazz = Class.forName("org.nutz.dao.impl.SimpleDataSource");
        SimpleDataSource dataSource = (SimpleDataSource) clazz.newInstance();
        dataSource.setDriverClassName("com.beyondb.jdbc.BeyondbDriver");
        
    }
}

@qq_ff330a3f 我晕啊,既然有driverClassName属性,在js里面设置一下不就完了

跟username password一样的配法

@wendal 我在js里面配置了之后还是报错,这该怎么办呢?兽总

贴你现在的dao.js

var ioc = {
    dao : {
        type : "org.nutz.dao.impl.NutDao",
        args : [{refer:"dataSource"}]
    },
    dataSource : {
        type : "org.nutz.dao.impl.SimpleDataSource",
        fields : {
            jdbcUrl : 'jdbc:beyondb://192.168.1.55:II7/shuiwen;auto=multi;TZ=HONG-KONG',
            driverClassName : "com.beyondb.jdbc.BeyondbDriver",
            username : 'shuiwen',
            password : '123456'
        }
    }
}

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