小编sta*_*ack的帖子

java - 从excel导入到mysql

我有列的 excel 文件 (.xlsx)

Column1     Column2      Column3      Column1
   A           50          30           40
   B           45          40           20
   .......................................
Run Code Online (Sandbox Code Playgroud)

我需要在 MySQL 数据库中导入这个 excel。我使用以下代码:

 public static void main(String[] args) throws IOException {

    FileInputStream fis = new FileInputStream(new File("Data.xlsx"));
    XSSFWorkbook workbook = new XSSFWorkbook (fis);
    XSSFSheet sheet = workbook.getSheetAt(0);
    Iterator ite = sheet.rowIterator();
    while(ite.hasNext()){
        Row row = (Row) ite.next();
        Iterator<Cell> cite = row.cellIterator();
        while(cite.hasNext()){
            Cell c = cite.next();
            System.out.print(c.toString() +";");
        }
        System.out.println();
    }
    fis.close();
}
Run Code Online (Sandbox Code Playgroud)

我需要列出所有行。此代码在控制台中显示行中的所有数据,但我现在不将该数据添加到列表中并将列表导入到 MySQL。

任何的想法?

java import excel

1
推荐指数
1
解决办法
2220
查看次数

标签 统计

excel ×1

import ×1

java ×1