提高阅读和持久化Apache POI excel文件的速度

时间:2013-03-29 23:07:10

标签: java mysql apache jpa apache-poi

我有一个Excel文件,我目前能够导入到mySQL数据库中,但我想稍微提高导入的速度。我设置读取Excel文件(每个文件大约40,000行,10-15列)并保持不变如下:

* Java Code *

public void importFileToDataBase(String file) {
        try {
            FileInputStream latestExcelFile = new FileInputStream(file);
            wb = WorkbookFactory.create(myFile);
        } catch (Exception ex) {
        }

        Sheet bigSheet = wb.getSheetAt(0);

        for (int i = 1; i <= bigSheet.getLastRowNum(); i++) {

            try {

                row = bigSheet.getRow(i);
                String bigSheetId = i + "";
                Date column1 = row.getCell(0).getDateCellValue();
                int column2 = (int) row.getCell(1).getNumericCellValue();
                int column3 = (int) row.getCell(3).getNumericCellValue();
                int column4 = (int) row.getCell(4).getNumericCellValue();
                int column5 = (int) row.getCell(5).getNumericCellValue();
                int column6 = (int) row.getCell(6).getNumericCellValue();
                int column7 = (int) row.getCell(7).getNumericCellValue();
                String column8 = row.getCell(9).toString();
                String column9 = row.getCell(11).toString();
                String column10 = row.getCell(12).toString();
                String column11 = row.getCell(13).toString();
                int column12 = (int) row.getCell(8).getNumericCellValue();
                Double column13 = row.getCell(10).getNumericCellValue();
                String column14 = row.getCell(2)
                        .toString();

                BigSheet mySheet = new BigSheet(
                        baseDataTableId, column1, column2, column3, column4,
                        column5, column6, column7, column8, column9,
                        column10, column11, column12, column13, column14);

                putInDatabase(mySheet);
            } catch (Exception ex) {}
        }

有没有办法通过批处理提高导入速度?

如果是这样,你能举例说明如何做到这一点(如果可能的话)?

0 个答案:

没有答案