把oracel导出得xlsx导入到数据库-主要解决得问题是数据同步Clob大字段得时候报错

将xlsx导入到数据库

解决得问题:应为在同步大字段(clob)到数据库得时候,会出现问题,所有我们先把数据库中的数据导出成xlsx文件然后,再把它入库。

public List<PipeConfig> importExcelAction() throws Exception {
//文件路径
        String webPath = FileUtil.getWebPath("/excelImportTemp/");
        String filePath = webPath+"/tmp001.xlsx";
        XSSFWorkbook wookbook = new XSSFWorkbook(new FileInputStream(filePath));
        XSSFSheet sheet = wookbook.getSheet("SQL Results");
        //获取到Excel文件中的所有行数
        int rows = sheet.getPhysicalNumberOfRows();
        //遍历行
        List<PipeConfig> pipelist = new ArrayList<PipeConfig>();
        for (int i = 1; i < rows; i++) {
            // 读取左上端单元格
            XSSFRow row = sheet.getRow(i);
            // 行不为空
            if (row != null) {
                //获取到Excel文件中的所有的列
                int cells = row.getPhysicalNumberOfCells();
                XSSFCell pkIdCell = row.getCell(1);
                String pkId = getValue(pkIdCell);
                XSSFCell ifCodeCell = row.getCell(2);
                String ifCode = getValue(ifCodeCell);
                XSSFCell ifNameCell = row.getCell(3);
                String ifName = getValue(ifNameCell);
                XSSFCell ifTypeCell = row.getCell(4);
                String ifType = getValue(ifTypeCell);
                XSSFCell fileNameCell = row.getCell(5);
                String fileName = getValue(fileNameCell);
                XSSFCell fileTypeCell = row.getCell(6);
                String fileType = getValue(fileTypeCell);
                XSSFCell encodingTypeCell = row.getCell(7);
                String encodingType = getValue(encodingTypeCell);
                XSSFCell specialArgsCell = row.getCell(8);
                String specialArgs = getValue(specialArgsCell);
                XSSFCell execTypeCell = row.getCell(9);
                String execType = getValue(execTypeCell);
                XSSFCell headSqlCell = row.getCell(10);
                String headSql = getValue(headSqlCell);
                XSSFCell tailSqlCell = row.getCell(11);
                String tailSql = getValue(tailSqlCell);
                XSSFCell confDetailsCell = row.getCell(12);
                String confDetails = getValue(confDetailsCell);
             //   confDetails = confDetails.replace("'","''");
                XSSFCell statusCell = row.getCell(13);
                String status = getValue(statusCell);
                XSSFCell deletedCell = row.getCell(14);
                String deleted = getValue(deletedCell);
                XSSFCell createdTsCell = row.getCell(15);
                String createdTs = getValue(createdTsCell);
                XSSFCell createdByCell = row.getCell(16);
                String createdBy = getValue(createdByCell);
                XSSFCell updatedTsCell = row.getCell(17);
                String updatedTs = getValue(updatedTsCell);
                XSSFCell updatedByCell = row.getCell(18);
                String updatedBy = getValue(updatedByCell);
                PipeConfig pipeConfig = new PipeConfig(pkId,ifCode,ifName,ifType,fileName,fileType,encodingType,specialArgs,
                        execType,headSql,tailSql,confDetails,status,deleted,createdTs,createdBy,updatedTs,updatedBy);
                pipelist.add(pipeConfig);
            }
        }
        return pipelist;
    }

    private String getValue(XSSFCell xSSFCell) {
        if (null == xSSFCell) {
            return "";
        }
        if (xSSFCell.getCellType() == 4) {
        // 返回布尔类型的值  
            return String.valueOf(xSSFCell.getBooleanCellValue());
        } else if (xSSFCell.getCellType() == 0) {
        // 返回数值类型的值  
            return String.valueOf(xSSFCell.getNumericCellValue());
        } else {
        // 返回字符串类型的值  
            return String.valueOf(xSSFCell.getStringCellValue());
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值