表名参数化
This commit is contained in:
		
							
								
								
									
										3
									
								
								代码/jsp/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								代码/jsp/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +1,2 @@
 | 
			
		||||
.idea/workspace.xml
 | 
			
		||||
out/
 | 
			
		||||
dataSources/
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								代码/jsp/.idea/codeStyles/codeStyleConfig.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								代码/jsp/.idea/codeStyles/codeStyleConfig.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
<component name="ProjectCodeStyleConfiguration">
 | 
			
		||||
  <state>
 | 
			
		||||
    <option name="PREFERRED_PROJECT_CODE_STYLE" value="Kane" />
 | 
			
		||||
  </state>
 | 
			
		||||
</component>
 | 
			
		||||
@@ -24,21 +24,18 @@ public class DataImport
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 读取xls表格插入数据,要么全部成功,要么全部失败。
 | 
			
		||||
     * @param fileName xls文件名
 | 
			
		||||
     * @param oracleURL oracle数据库URL
 | 
			
		||||
     * @param oracleUserName oracle用户名
 | 
			
		||||
     * @param oraclePassword oracle密码
 | 
			
		||||
     * @param informixURL informix数据库URL
 | 
			
		||||
     *
 | 
			
		||||
     * @param fileName                           xls文件名
 | 
			
		||||
     * @param telsalePolicyOperatorListTableName informix库电销转介绍表名
 | 
			
		||||
     * @param informixURL                        informix数据库URL
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws IOException
 | 
			
		||||
     * @throws ClassNotFoundException
 | 
			
		||||
     * @throws SQLException 数据库异常
 | 
			
		||||
     * @throws SQLException           数据库异常
 | 
			
		||||
     * @throws XlsFileFormatException xls文件格式错误异常
 | 
			
		||||
     */
 | 
			
		||||
    public static String importTelsalePolicyDataFromXlsx( String fileName,
 | 
			
		||||
                                                          String oracleURL,
 | 
			
		||||
                                                          String oracleUserName,
 | 
			
		||||
                                                          String oraclePassword,
 | 
			
		||||
                                                          String telsalePolicyOperatorListTableName,
 | 
			
		||||
                                                          String informixURL ) throws
 | 
			
		||||
            IOException,
 | 
			
		||||
            ClassNotFoundException,
 | 
			
		||||
@@ -47,9 +44,9 @@ public class DataImport
 | 
			
		||||
    {
 | 
			
		||||
        String importResult = "";
 | 
			
		||||
        String importMessage = null;
 | 
			
		||||
        int rowCount = 1;
 | 
			
		||||
        int successCount = 0;
 | 
			
		||||
        int failCount = 0;
 | 
			
		||||
        int rowCount = 1; //excel文件行索引
 | 
			
		||||
        int successCount = 0; //成功写入的行计数
 | 
			
		||||
        int failCount = 0; //写入失败的行计数
 | 
			
		||||
 | 
			
		||||
        //excel相关
 | 
			
		||||
        FileInputStream xlsFileIn = null;
 | 
			
		||||
@@ -61,7 +58,7 @@ public class DataImport
 | 
			
		||||
        {
 | 
			
		||||
            xlsFileIn = new FileInputStream( fileName );
 | 
			
		||||
            xlsFile = new HSSFWorkbook( xlsFileIn );
 | 
			
		||||
            sheet = xlsFile.getSheet( "Sheet1" );
 | 
			
		||||
            sheet = xlsFile.getSheetAt( 0 ); //第一个sheet
 | 
			
		||||
            row = sheet.getRow( rowCount );
 | 
			
		||||
        }
 | 
			
		||||
        catch( IOException error ) //有文件格式错误的可能。
 | 
			
		||||
@@ -72,47 +69,10 @@ public class DataImport
 | 
			
		||||
            throw new XlsFileFormatException( "文件格式错误,请检查是否xls格式文件。" );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //oracle相关
 | 
			
		||||
        Class.forName( "oracle.jdbc.driver.OracleDriver" );
 | 
			
		||||
 | 
			
		||||
        Connection oracleConn = null;
 | 
			
		||||
        PreparedStatement oracleStmt = null;
 | 
			
		||||
        String oraSql =
 | 
			
		||||
                "INSERT INTO telsale_oper_lst\n" +
 | 
			
		||||
                        "    (policy_no,\n" +
 | 
			
		||||
                        "     operator_code,\n" +
 | 
			
		||||
                        "     operator_name,\n" +
 | 
			
		||||
                        "     section_office_code,\n" +
 | 
			
		||||
                        "     section_office_name,\n" +
 | 
			
		||||
                        "     department_code,\n" +
 | 
			
		||||
                        "     department_name,\n" +
 | 
			
		||||
                        "     autotrader_code,\n" +
 | 
			
		||||
                        "     insruant_name,\n" +
 | 
			
		||||
                        "     plate_no,\n" +
 | 
			
		||||
                        "     entry_staff_code,\n" +
 | 
			
		||||
                        "     entry_date)\n" +
 | 
			
		||||
                        "VALUES\n" +
 | 
			
		||||
                        "    (?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     ?,\n" +
 | 
			
		||||
                        "     '800',\n" +
 | 
			
		||||
                        "     SYSDATE)";
 | 
			
		||||
 | 
			
		||||
        oracleConn = DriverManager.getConnection( oracleURL, oracleUserName, oraclePassword );
 | 
			
		||||
        oracleConn.setAutoCommit( false );//关闭自动提交,整个表格要么全部成写入,要么全部失败。
 | 
			
		||||
        oracleStmt = oracleConn.prepareStatement( oraSql );
 | 
			
		||||
 | 
			
		||||
        //informix相关
 | 
			
		||||
        Class.forName( "com.informix.jdbc.IfxDriver" );
 | 
			
		||||
        String ifxSql =
 | 
			
		||||
                "INSERT INTO w_dxbd_i\n" +
 | 
			
		||||
                "INSERT INTO " + telsalePolicyOperatorListTableName + " \n" +
 | 
			
		||||
                        "    (bdh,\n" +
 | 
			
		||||
                        "     zhjywy,\n" +
 | 
			
		||||
                        "     zhjywymc,\n" +
 | 
			
		||||
@@ -174,20 +134,6 @@ public class DataImport
 | 
			
		||||
                    //取得经办人信息
 | 
			
		||||
                    staff = new StaffInfo( operatorCode );
 | 
			
		||||
 | 
			
		||||
                    //写入oracle
 | 
			
		||||
//                    oracleStmt.setString( 1, policyNo );
 | 
			
		||||
//                    oracleStmt.setString( 2, staff.getStaffCode() );
 | 
			
		||||
//                    oracleStmt.setString( 3, staff.getStaffName() );
 | 
			
		||||
//                    oracleStmt.setString( 4, staff.getSectionOfficeCode() );
 | 
			
		||||
//                    oracleStmt.setString( 5, staff.getSectionOfficeName() );
 | 
			
		||||
//                    oracleStmt.setString( 6, staff.getDepartmentCode() );
 | 
			
		||||
//                    oracleStmt.setString( 7, staff.getDepartmentName() );
 | 
			
		||||
//                    oracleStmt.setString( 8, getStringValueFromHSSFCell( row.getCell( 6 ) ) );
 | 
			
		||||
//                    oracleStmt.setString( 9, getStringValueFromHSSFCell( row.getCell( 3 ) ) );
 | 
			
		||||
//                    oracleStmt.setString( 10, getStringValueFromHSSFCell( row.getCell( 2 ) ) );
 | 
			
		||||
//
 | 
			
		||||
//                    oracleStmt.execute();
 | 
			
		||||
 | 
			
		||||
                    //写入informix
 | 
			
		||||
                    ifxStmt.setString( 1, policyNo );
 | 
			
		||||
                    ifxStmt.setString( 2, staff.getStaffCode() );
 | 
			
		||||
@@ -201,6 +147,8 @@ public class DataImport
 | 
			
		||||
                    ifxStmt.setString( 10, getStringValueFromHSSFCell( row.getCell( 2 ) ) );
 | 
			
		||||
 | 
			
		||||
                    ifxStmt.execute();
 | 
			
		||||
 | 
			
		||||
                    successCount++;
 | 
			
		||||
                }
 | 
			
		||||
                catch( StaffCodeNotExistException error )
 | 
			
		||||
                {
 | 
			
		||||
@@ -209,6 +157,9 @@ public class DataImport
 | 
			
		||||
 | 
			
		||||
                    //标志位
 | 
			
		||||
                    isSuccess = false;
 | 
			
		||||
 | 
			
		||||
                    //计数
 | 
			
		||||
                    failCount++;
 | 
			
		||||
                }
 | 
			
		||||
                catch( SQLException error )
 | 
			
		||||
                {
 | 
			
		||||
@@ -217,6 +168,20 @@ public class DataImport
 | 
			
		||||
 | 
			
		||||
                    //标志位
 | 
			
		||||
                    isSuccess = false;
 | 
			
		||||
 | 
			
		||||
                    //计数
 | 
			
		||||
                    failCount++;
 | 
			
		||||
                }
 | 
			
		||||
                catch( Exception error )
 | 
			
		||||
                {
 | 
			
		||||
                    //写入错误
 | 
			
		||||
                    importResult = importResult + "第" + rowCount + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。<br>";
 | 
			
		||||
 | 
			
		||||
                    //标志位
 | 
			
		||||
                    isSuccess = false;
 | 
			
		||||
 | 
			
		||||
                    //计数
 | 
			
		||||
                    failCount++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -227,25 +192,36 @@ public class DataImport
 | 
			
		||||
        //判断标志位,如果为false,则说明在保存过程中出现了错误,放弃所有过程,进行回滚。
 | 
			
		||||
        if ( isSuccess == true )
 | 
			
		||||
        {
 | 
			
		||||
            oracleConn.commit();
 | 
			
		||||
            //oracleConn.commit();
 | 
			
		||||
            ifxConn.commit();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            oracleConn.rollback();
 | 
			
		||||
            ifxConn.rollback();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //清理
 | 
			
		||||
        oracleConn.close();
 | 
			
		||||
        xlsFile.close();
 | 
			
		||||
        xlsFileIn.close();
 | 
			
		||||
 | 
			
		||||
        //日志
 | 
			
		||||
        importMessage = "记录数量:" + (rowCount - 1) +
 | 
			
		||||
                "<br>导入成功数量:" + successCount +
 | 
			
		||||
                "<br>导入失败数量:" + failCount +
 | 
			
		||||
                "<br>" + importResult;
 | 
			
		||||
        importMessage = "读取记录数量:" + (rowCount - 1) +
 | 
			
		||||
                "<br>正确记录数量:" + successCount +
 | 
			
		||||
                "<br>错误记录数量:" + failCount;
 | 
			
		||||
 | 
			
		||||
        if ( failCount != 0 )
 | 
			
		||||
        {
 | 
			
		||||
            //有错误的记录,输出提示
 | 
			
		||||
            importMessage += "<br>请根据错误提示修正后重新导入!<br>";
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            //无错误的记录,输出成功提示
 | 
			
		||||
            importMessage += "<br>文件已成功导入!<br>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //追加导入记录
 | 
			
		||||
        importMessage += importResult;
 | 
			
		||||
 | 
			
		||||
        return importMessage;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -19,24 +19,23 @@ import com.cpic.telsale.DataImport.*;
 | 
			
		||||
public class uploadDataProcessor extends HttpServlet
 | 
			
		||||
{
 | 
			
		||||
    private String tempPathRoot; //临时文件目录
 | 
			
		||||
    private String oracleURL;
 | 
			
		||||
    private String oracleUserName;
 | 
			
		||||
    private String oraclePassword;
 | 
			
		||||
//    private String oracleURL;
 | 
			
		||||
//    private String oracleUserName;
 | 
			
		||||
//    private String oraclePassword;
 | 
			
		||||
    private String informixURL;
 | 
			
		||||
    private String telsalePolicyOperatorListTableName; //informix库电销转介绍表名
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void init( ServletConfig config ) throws ServletException
 | 
			
		||||
    {
 | 
			
		||||
        //获取参数
 | 
			
		||||
        //tempPathRoot = ( String )config.getServletContext().getAttribute( "临时文件根目录" );
 | 
			
		||||
 | 
			
		||||
        //oracle
 | 
			
		||||
        oracleURL = ( String )config.getServletContext().getInitParameter( "oracleURL" );
 | 
			
		||||
        oracleUserName = ( String )config.getServletContext().getInitParameter( "oracleUserName" );
 | 
			
		||||
        oraclePassword = ( String )config.getServletContext().getInitParameter( "oraclePassword" );
 | 
			
		||||
//        oracleURL = ( String )config.getServletContext().getInitParameter( "oracleURL" );
 | 
			
		||||
//        oracleUserName = ( String )config.getServletContext().getInitParameter( "oracleUserName" );
 | 
			
		||||
//        oraclePassword = ( String )config.getServletContext().getInitParameter( "oraclePassword" );
 | 
			
		||||
 | 
			
		||||
        //informix
 | 
			
		||||
        informixURL = ( String )config.getServletContext().getInitParameter( "informixURL" );
 | 
			
		||||
        telsalePolicyOperatorListTableName = (String)config.getServletContext().getInitParameter( "telsalePolicyOperatorListTableName" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -66,9 +65,7 @@ public class uploadDataProcessor extends HttpServlet
 | 
			
		||||
                    String upLoadedFileName = saveUploadedFile( fileItem );
 | 
			
		||||
 | 
			
		||||
                    importMessage = DataImport.importTelsalePolicyDataFromXlsx( upLoadedFileName,
 | 
			
		||||
                                                                                oracleURL,
 | 
			
		||||
                                                                                oracleUserName,
 | 
			
		||||
                                                                                oraclePassword,
 | 
			
		||||
                                                                                telsalePolicyOperatorListTableName,
 | 
			
		||||
                                                                                informixURL );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -35,6 +35,10 @@
 | 
			
		||||
        <param-name>informixURL</param-name>
 | 
			
		||||
        <param-value>jdbc:informix-sqli://10.39.0.92:16192/ywgl_xm:INFORMIXSERVER=xmcx2;newcodeset=GBK,8859-1,819;user=ccx99;password=c92IT09</param-value>
 | 
			
		||||
    </context-param>
 | 
			
		||||
    <context-param>
 | 
			
		||||
        <param-name>telsalePolicyOperatorListTableName</param-name>
 | 
			
		||||
        <param-value>w_dxbd_i1</param-value>
 | 
			
		||||
    </context-param>
 | 
			
		||||
 | 
			
		||||
    <!--Servlet设置-->
 | 
			
		||||
    <servlet>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								代码/jsp/web/doc/电销转介绍导入模板.xls
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								代码/jsp/web/doc/电销转介绍导入模板.xls
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -26,6 +26,8 @@
 | 
			
		||||
    <input type="submit" name="upload" value="<22>ϴ<EFBFBD>">
 | 
			
		||||
    <input type="reset" name="reset" value="<22><><EFBFBD><EFBFBD>">
 | 
			
		||||
</form>
 | 
			
		||||
<a href="../doc/<2F><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>ģ<EFBFBD><C4A3>.xls" style="color:red;"><3E><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD></a>
 | 
			
		||||
<p style="display: inline"><3E><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>š<EFBFBD><C5A1><EFBFBD><EFBFBD>ƺš<C6BA><C5A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˡ<EFBFBD><CBA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4>롢<EFBFBD><EBA1A2><EFBFBD>̴<EFBFBD><CCB4><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD></p>
 | 
			
		||||
<!--<2D>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ-->
 | 
			
		||||
<%
 | 
			
		||||
    int uploadCount = 0;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user