From 332d77a208aaa05dcabd5e9b6f0650a0f30f753d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=82=9C?= Date: Thu, 26 Jul 2018 17:34:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cpic/telsale/DataImport/DataImport.java | 32 +++++++++++++------ 代码/jsp/telsale_import/web/WEB-INF/web.xml | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/代码/jsp/telsale_import/src/com/cpic/telsale/DataImport/DataImport.java b/代码/jsp/telsale_import/src/com/cpic/telsale/DataImport/DataImport.java index 8e99be9..8a1a928 100644 --- a/代码/jsp/telsale_import/src/com/cpic/telsale/DataImport/DataImport.java +++ b/代码/jsp/telsale_import/src/com/cpic/telsale/DataImport/DataImport.java @@ -44,7 +44,8 @@ public class DataImport { String importResult = ""; String importMessage = null; - int rowCount = 1; //excel文件行索引 + int rowIndex = 1; //excel文件行索引 + int rowCount = -1; int successCount = 0; //成功写入的行计数 int failCount = 0; //写入失败的行计数 @@ -59,7 +60,9 @@ public class DataImport xlsFileIn = new FileInputStream( fileName ); xlsFile = new HSSFWorkbook( xlsFileIn ); sheet = xlsFile.getSheetAt( 0 ); //第一个sheet - row = sheet.getRow( rowCount ); + rowIndex = sheet.getFirstRowNum() + 1; + rowCount = sheet.getLastRowNum(); + row = sheet.getRow( rowIndex ); } catch( IOException error ) //有文件格式错误的可能。 { @@ -115,15 +118,24 @@ public class DataImport StaffInfo staff = null; boolean isSuccess = true; //标志位,用来指示在保存过程中是否出现错误。 - while ( row != null ) + while ( rowIndex <= rowCount ) { + //用来判断是不是空行 + HSSFCell cell = row.getCell( 0 ); + + if ( cell == null) + { + rowIndex++; + continue; + } + policyNo = row.getCell( 0 ).getStringCellValue().trim(); operatorCode = getStringValueFromHSSFCell( row.getCell( 1 ) ); //判断一下是不是空的单元格 if ( policyNo.length() == 0 || operatorCode.length() == 0 ) { - importResult = importResult + "第" + rowCount + "行数据为空。
"; + importResult = importResult + "第" + rowIndex + "行数据为空。
"; //isSuccess = false; } @@ -153,7 +165,7 @@ public class DataImport catch( StaffCodeNotExistException error ) { //经办人不存在 - importResult = importResult + "第" + rowCount + "行,保单号" + policyNo + ",经办人" + operatorCode + "不存在。
"; + importResult = importResult + "第" + rowIndex + "行,保单号" + policyNo + ",经办人" + operatorCode + "不存在。
"; //标志位 isSuccess = false; @@ -164,7 +176,7 @@ public class DataImport catch( SQLException error ) { //写入错误 - importResult = importResult + "第" + rowCount + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。
"; + importResult = importResult + "第" + rowIndex + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。
"; //标志位 isSuccess = false; @@ -175,7 +187,7 @@ public class DataImport catch( Exception error ) { //写入错误 - importResult = importResult + "第" + rowCount + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。
"; + importResult = importResult + "第" + rowIndex + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。
"; //标志位 isSuccess = false; @@ -185,8 +197,8 @@ public class DataImport } } - rowCount++; - row = sheet.getRow( rowCount ); + rowIndex++; + row = sheet.getRow( rowIndex ); } //判断标志位,如果为false,则说明在保存过程中出现了错误,放弃所有过程,进行回滚。 @@ -205,7 +217,7 @@ public class DataImport xlsFileIn.close(); //日志 - importMessage = "读取记录数量:" + (rowCount - 1) + + importMessage = "读取记录数量:" + (rowIndex - 1) + "
正确记录数量:" + successCount + "
错误记录数量:" + failCount; diff --git a/代码/jsp/telsale_import/web/WEB-INF/web.xml b/代码/jsp/telsale_import/web/WEB-INF/web.xml index 69352fa..e4869a1 100644 --- a/代码/jsp/telsale_import/web/WEB-INF/web.xml +++ b/代码/jsp/telsale_import/web/WEB-INF/web.xml @@ -33,7 +33,7 @@ informixURL - jdbc:informix-sqli://10.39.0.92:16192/ywgl_xm:INFORMIXSERVER=xmcx2;newcodeset=GBK,8859-1,819;user=ccx99;password=c92IT09 + jdbc:informix-sqli://10.187.11.163:9096/ywgl_xm:INFORMIXSERVER=pxmcx2;newcodeset=GBK,8859-1,819;user=ccx99;password=ct0IT17! telsalePolicyOperatorListTableName