使用jsp / servlet将excel数据上传到数据库中

1)如何开发一个将excel中的所有数据转移到oracle数据库的软件?

2)excel表格中的单元格可能会根据用户给出的input而有所不同,因此我们必须dynamic读取excel并根据列值创build登台表格。

好心地build议我一个想法如何做到这一点,如果可能的话,build议我一个示例链接

提前致谢

使用浏览button阅读文件名

fileName = new File(item.getName()).getName(); String filePath = uploadPath + File.separator + fileName; //System.out.println("File Name : "+fileName); //System.out.println("File Path : "+filePath); File storeFile = new File(filePath); // saves the file on disk if(fileName != null && fileName.length()>0){ System.out.println("Store File : "+fileName); item.write(storeFile); fileInp=item.getInputStream(); 

读取给定的Excel文件

  System.out.println("Started reading Excel File"); String[] title = new String[6]; String[] val = new String[6]; workbook = new HSSFWorkbook(fileInp); Sheet worksheet = workbook.getSheetAt(0); rowCount = worksheet.getLastRowNum(); Row row = worksheet.getRow(0); Cell col1 = row.getCell((short) 0); title[0] = col1.getStringCellValue(); Cell col2 = row.getCell((short) 1); title[1] = col2.getStringCellValue(); Cell col3 = row.getCell((short) 2); title[2] = col3.getStringCellValue(); Cell col4 = row.getCell((short) 3); title[3] = col4.getStringCellValue(); Cell col5 = row.getCell((short) 4); title[4] = col5.getStringCellValue(); Cell col6 = row.getCell((short) 5); title[5] = col6.getStringCellValue(); for (int i = 1; i <= rowCount; i++) { row = worksheet.getRow(i); Cell col; for (int j = 0; j < 6; j++) { col = row.getCell((short) j); if (col != null) { col.setCellType(HSSFCell.CELL_TYPE_STRING); val[j] = col.getStringCellValue(); /* * switch (col.getCellType()) { case * HSSFCell.CELL_TYPE_STRING: val[j] = * col.getStringCellValue(); break; case * HSSFCell.CELL_TYPE_NUMERIC: val[j] = * col.getNumericCellValue() + ""; break; } */ } } 

除此之外,我需要做一个dynamic的方式相同的过程中,在上述情况下,我已经预先定义了列,但我需要编写一个代码,我应该生成一个表,数据库

一种可能的方法是使用Apache Poi逐行读取Excel表格。

一旦获得数据,就可以使用JDBC驱动程序将数据填充到数据库中。