表名参数化
This commit is contained in:
parent
a319843c16
commit
ecf50ef77e
|
@ -1,3 +1,2 @@
|
||||||
.idea/workspace.xml
|
.idea/workspace.xml
|
||||||
out/
|
|
||||||
dataSources/
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Kane" />
|
||||||
|
</state>
|
||||||
|
</component>
|
|
@ -24,10 +24,9 @@ public class DataImport
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取xls表格插入数据,要么全部成功,要么全部失败。
|
* 读取xls表格插入数据,要么全部成功,要么全部失败。
|
||||||
|
*
|
||||||
* @param fileName xls文件名
|
* @param fileName xls文件名
|
||||||
* @param oracleURL oracle数据库URL
|
* @param telsalePolicyOperatorListTableName informix库电销转介绍表名
|
||||||
* @param oracleUserName oracle用户名
|
|
||||||
* @param oraclePassword oracle密码
|
|
||||||
* @param informixURL informix数据库URL
|
* @param informixURL informix数据库URL
|
||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
@ -36,9 +35,7 @@ public class DataImport
|
||||||
* @throws XlsFileFormatException xls文件格式错误异常
|
* @throws XlsFileFormatException xls文件格式错误异常
|
||||||
*/
|
*/
|
||||||
public static String importTelsalePolicyDataFromXlsx( String fileName,
|
public static String importTelsalePolicyDataFromXlsx( String fileName,
|
||||||
String oracleURL,
|
String telsalePolicyOperatorListTableName,
|
||||||
String oracleUserName,
|
|
||||||
String oraclePassword,
|
|
||||||
String informixURL ) throws
|
String informixURL ) throws
|
||||||
IOException,
|
IOException,
|
||||||
ClassNotFoundException,
|
ClassNotFoundException,
|
||||||
|
@ -47,9 +44,9 @@ public class DataImport
|
||||||
{
|
{
|
||||||
String importResult = "";
|
String importResult = "";
|
||||||
String importMessage = null;
|
String importMessage = null;
|
||||||
int rowCount = 1;
|
int rowCount = 1; //excel文件行索引
|
||||||
int successCount = 0;
|
int successCount = 0; //成功写入的行计数
|
||||||
int failCount = 0;
|
int failCount = 0; //写入失败的行计数
|
||||||
|
|
||||||
//excel相关
|
//excel相关
|
||||||
FileInputStream xlsFileIn = null;
|
FileInputStream xlsFileIn = null;
|
||||||
|
@ -61,7 +58,7 @@ public class DataImport
|
||||||
{
|
{
|
||||||
xlsFileIn = new FileInputStream( fileName );
|
xlsFileIn = new FileInputStream( fileName );
|
||||||
xlsFile = new HSSFWorkbook( xlsFileIn );
|
xlsFile = new HSSFWorkbook( xlsFileIn );
|
||||||
sheet = xlsFile.getSheet( "Sheet1" );
|
sheet = xlsFile.getSheetAt( 0 ); //第一个sheet
|
||||||
row = sheet.getRow( rowCount );
|
row = sheet.getRow( rowCount );
|
||||||
}
|
}
|
||||||
catch( IOException error ) //有文件格式错误的可能。
|
catch( IOException error ) //有文件格式错误的可能。
|
||||||
|
@ -72,47 +69,10 @@ public class DataImport
|
||||||
throw new XlsFileFormatException( "文件格式错误,请检查是否xls格式文件。" );
|
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相关
|
//informix相关
|
||||||
Class.forName( "com.informix.jdbc.IfxDriver" );
|
Class.forName( "com.informix.jdbc.IfxDriver" );
|
||||||
String ifxSql =
|
String ifxSql =
|
||||||
"INSERT INTO w_dxbd_i\n" +
|
"INSERT INTO " + telsalePolicyOperatorListTableName + " \n" +
|
||||||
" (bdh,\n" +
|
" (bdh,\n" +
|
||||||
" zhjywy,\n" +
|
" zhjywy,\n" +
|
||||||
" zhjywymc,\n" +
|
" zhjywymc,\n" +
|
||||||
|
@ -174,20 +134,6 @@ public class DataImport
|
||||||
//取得经办人信息
|
//取得经办人信息
|
||||||
staff = new StaffInfo( operatorCode );
|
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
|
//写入informix
|
||||||
ifxStmt.setString( 1, policyNo );
|
ifxStmt.setString( 1, policyNo );
|
||||||
ifxStmt.setString( 2, staff.getStaffCode() );
|
ifxStmt.setString( 2, staff.getStaffCode() );
|
||||||
|
@ -201,6 +147,8 @@ public class DataImport
|
||||||
ifxStmt.setString( 10, getStringValueFromHSSFCell( row.getCell( 2 ) ) );
|
ifxStmt.setString( 10, getStringValueFromHSSFCell( row.getCell( 2 ) ) );
|
||||||
|
|
||||||
ifxStmt.execute();
|
ifxStmt.execute();
|
||||||
|
|
||||||
|
successCount++;
|
||||||
}
|
}
|
||||||
catch( StaffCodeNotExistException error )
|
catch( StaffCodeNotExistException error )
|
||||||
{
|
{
|
||||||
|
@ -209,6 +157,9 @@ public class DataImport
|
||||||
|
|
||||||
//标志位
|
//标志位
|
||||||
isSuccess = false;
|
isSuccess = false;
|
||||||
|
|
||||||
|
//计数
|
||||||
|
failCount++;
|
||||||
}
|
}
|
||||||
catch( SQLException error )
|
catch( SQLException error )
|
||||||
{
|
{
|
||||||
|
@ -217,6 +168,20 @@ public class DataImport
|
||||||
|
|
||||||
//标志位
|
//标志位
|
||||||
isSuccess = false;
|
isSuccess = false;
|
||||||
|
|
||||||
|
//计数
|
||||||
|
failCount++;
|
||||||
|
}
|
||||||
|
catch( Exception error )
|
||||||
|
{
|
||||||
|
//写入错误
|
||||||
|
importResult = importResult + "第" + rowCount + "行,保单号" + policyNo + ",数据库写入错误,错误信息:" + error.getMessage() + "。<br>";
|
||||||
|
|
||||||
|
//标志位
|
||||||
|
isSuccess = false;
|
||||||
|
|
||||||
|
//计数
|
||||||
|
failCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,25 +192,36 @@ public class DataImport
|
||||||
//判断标志位,如果为false,则说明在保存过程中出现了错误,放弃所有过程,进行回滚。
|
//判断标志位,如果为false,则说明在保存过程中出现了错误,放弃所有过程,进行回滚。
|
||||||
if ( isSuccess == true )
|
if ( isSuccess == true )
|
||||||
{
|
{
|
||||||
oracleConn.commit();
|
//oracleConn.commit();
|
||||||
ifxConn.commit();
|
ifxConn.commit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
oracleConn.rollback();
|
|
||||||
ifxConn.rollback();
|
ifxConn.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
//清理
|
//清理
|
||||||
oracleConn.close();
|
|
||||||
xlsFile.close();
|
xlsFile.close();
|
||||||
xlsFileIn.close();
|
xlsFileIn.close();
|
||||||
|
|
||||||
//日志
|
//日志
|
||||||
importMessage = "记录数量:" + (rowCount - 1) +
|
importMessage = "读取记录数量:" + (rowCount - 1) +
|
||||||
"<br>导入成功数量:" + successCount +
|
"<br>正确记录数量:" + successCount +
|
||||||
"<br>导入失败数量:" + failCount +
|
"<br>错误记录数量:" + failCount;
|
||||||
"<br>" + importResult;
|
|
||||||
|
if ( failCount != 0 )
|
||||||
|
{
|
||||||
|
//有错误的记录,输出提示
|
||||||
|
importMessage += "<br>请根据错误提示修正后重新导入!<br>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//无错误的记录,输出成功提示
|
||||||
|
importMessage += "<br>文件已成功导入!<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
//追加导入记录
|
||||||
|
importMessage += importResult;
|
||||||
|
|
||||||
return importMessage;
|
return importMessage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,24 +19,23 @@ import com.cpic.telsale.DataImport.*;
|
||||||
public class uploadDataProcessor extends HttpServlet
|
public class uploadDataProcessor extends HttpServlet
|
||||||
{
|
{
|
||||||
private String tempPathRoot; //临时文件目录
|
private String tempPathRoot; //临时文件目录
|
||||||
private String oracleURL;
|
// private String oracleURL;
|
||||||
private String oracleUserName;
|
// private String oracleUserName;
|
||||||
private String oraclePassword;
|
// private String oraclePassword;
|
||||||
private String informixURL;
|
private String informixURL;
|
||||||
|
private String telsalePolicyOperatorListTableName; //informix库电销转介绍表名
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init( ServletConfig config ) throws ServletException
|
public void init( ServletConfig config ) throws ServletException
|
||||||
{
|
{
|
||||||
//获取参数
|
//获取参数
|
||||||
//tempPathRoot = ( String )config.getServletContext().getAttribute( "临时文件根目录" );
|
// oracleURL = ( String )config.getServletContext().getInitParameter( "oracleURL" );
|
||||||
|
// oracleUserName = ( String )config.getServletContext().getInitParameter( "oracleUserName" );
|
||||||
//oracle
|
// 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
|
//informix
|
||||||
informixURL = ( String )config.getServletContext().getInitParameter( "informixURL" );
|
informixURL = ( String )config.getServletContext().getInitParameter( "informixURL" );
|
||||||
|
telsalePolicyOperatorListTableName = (String)config.getServletContext().getInitParameter( "telsalePolicyOperatorListTableName" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,9 +65,7 @@ public class uploadDataProcessor extends HttpServlet
|
||||||
String upLoadedFileName = saveUploadedFile( fileItem );
|
String upLoadedFileName = saveUploadedFile( fileItem );
|
||||||
|
|
||||||
importMessage = DataImport.importTelsalePolicyDataFromXlsx( upLoadedFileName,
|
importMessage = DataImport.importTelsalePolicyDataFromXlsx( upLoadedFileName,
|
||||||
oracleURL,
|
telsalePolicyOperatorListTableName,
|
||||||
oracleUserName,
|
|
||||||
oraclePassword,
|
|
||||||
informixURL );
|
informixURL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,10 @@
|
||||||
<param-name>informixURL</param-name>
|
<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>
|
<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>
|
||||||
|
<context-param>
|
||||||
|
<param-name>telsalePolicyOperatorListTableName</param-name>
|
||||||
|
<param-value>w_dxbd_i1</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
<!--Servlet设置-->
|
<!--Servlet设置-->
|
||||||
<servlet>
|
<servlet>
|
||||||
|
|
Binary file not shown.
|
@ -26,6 +26,8 @@
|
||||||
<input type="submit" name="upload" value="上传">
|
<input type="submit" name="upload" value="上传">
|
||||||
<input type="reset" name="reset" value="重置">
|
<input type="reset" name="reset" value="重置">
|
||||||
</form>
|
</form>
|
||||||
|
<a href="../doc/电销转介绍导入模板.xls" style="color:red;">导入模板下载</a>
|
||||||
|
<p style="display: inline">备注:保单号、车牌号、被保人、经办人代码、车商代码为必填项!</p>
|
||||||
<!--上传结果显示-->
|
<!--上传结果显示-->
|
||||||
<%
|
<%
|
||||||
int uploadCount = 0;
|
int uploadCount = 0;
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
DROP TABLE telsale_oper_lst;
|
||||||
|
CREATE TABLE telsale_oper_lst
|
||||||
|
(
|
||||||
|
policy_no VARCHAR2(20) PRIMARY KEY,
|
||||||
|
operator_code VARCHAR2(6) NOT NULL,
|
||||||
|
operator_name VARCHAR2(100 CHAR) NOT NULL,
|
||||||
|
section_office_code VARCHAR2(6) NOT NULL,
|
||||||
|
section_office_name VARCHAR2(100 CHAR) NOT NULL,
|
||||||
|
department_code VARCHAR2(6),
|
||||||
|
department_name VARCHAR2(100 CHAR),
|
||||||
|
autotrader_code VARCHAR2(30), --车商代码
|
||||||
|
insruant_name VARCHAR2(200 CHAR), --被保人名称
|
||||||
|
plate_no VARCHAR2(7 CHAR), --车牌号
|
||||||
|
entry_staff_code VARCHAR2(6) NOT NULL,
|
||||||
|
entry_date DATE DEFAULT SYSDATE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX telsale_oper_lst_i ON telsale_oper_lst(POLICY_NO,operator_code);
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
truncate table telsale_oper_lst;
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
INSERT INTO telsale_oper_lst
|
||||||
|
(policy_no,
|
||||||
|
operator_code,
|
||||||
|
operator_name,
|
||||||
|
section_office_code,
|
||||||
|
section_office_name,
|
||||||
|
department_code,
|
||||||
|
department_name,
|
||||||
|
autotrader_code,
|
||||||
|
insruant_name,
|
||||||
|
plate_no,
|
||||||
|
entry_staff_code,
|
||||||
|
entry_date)
|
||||||
|
VALUES
|
||||||
|
(?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
'800',
|
||||||
|
SYSDATE)
|
||||||
|
*/
|
||||||
|
SELECT * FROM telsale_oper_lst;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue