zoukankan      html  css  js  c++  java
  • 循环中出现异常时记录异常并继续执行循环

     for(AdminDataContent adminDataContent:adminDataContentList){
                     try {
                         String tableName=adminDataContent.getTableName();
                         String sql = "describe " +tableName ;  
                         PreparedStatement ps = conn.prepareStatement(sql);  
                         ResultSet resultset = ps.executeQuery();  
                         while(resultset.next()){
                                 AdminDataContentDetail contentDetail=new AdminDataContentDetail();
                                 contentDetail.setId(new UUIDUtils().getUUID());
                                 contentDetail.setContentId(adminDataContent.getId());
                                 contentDetail.setDatasourceId(adminDataContent.getDataSourceId());
                                 contentDetail.setColumnName(resultset.getString(1));
                                 contentDetail.setColumnType(resultset.getString(2));
                                 contentDetail.setCreateBy(adminDataContent.getCreateBy());
                                 contentDetail.setCreateDate(new Date());
                                 contentDetail.setUpdateBy(adminDataContent.getUpdateBy());
                                 contentDetail.setUpdateDate(new Date());
                                 contentDetail.setDelFlag("0");
                                 contentDetailsList.add(contentDetail);
                                   
                             }
                    } catch (Exception e) {
                        e.printStackTrace();
                         TableScanError error=new TableScanError();
                        error.setId(new UUIDUtils().getUUID());
                        error.setDataSourceId(adminDataContent.getDataSourceId());
                        error.setErrorTableName(adminDataContent.getTableName());
                        error.setErrorDatabase(StringUtils.substringBefore(adminDataContent.getTableName(), "."));
                        //error.setCreateBy(adminDataContent.getCreateBy());
                        error.setCreateDate(new Date());
                        //error.setUpdateBy(adminDataContent.getUpdateBy());
                        error.setUpdateDate(new Date());
                        error.setRemarks(e.toString());
                        errors.add(error);
                        continue;
                        
                    }       
                 }

    实例如上,在循环中使用try catch,catch中进行异常处理并使用continue进入下一次循环

  • 相关阅读:
    RESTful Web服务的操作
    Nginx学习之如何搭建文件防盗链服务
    PostgreSQL10.5安装详细步骤(Win10)
    前端安全系列(一):如何防止XSS攻击?
    【原码笔记】-- protobuf.js 与 Long.js
    【微信开发】-- 发送模板消息
    能编程与会编程
    vue2入坑随记(二) -- 自定义动态组件
    微信上传图片
    vue2入坑随记(一)-- 初始全家桶
  • 原文地址:https://www.cnblogs.com/dsh2018/p/9396919.html
Copyright © 2011-2022 走看看