-2

I want to insert data from excel file to MySQL database using JSP. once i select the excel file from jsp and give upload the entire file is getting uploaded. but i want to read the datas from excel sheet and insert that data into mysql database thanks in advance. can anyone tel me whether it is possible?

Community
  • 1
  • 1
Akmal
  • 71
  • 1
  • 2
  • 14
  • JSPs are used to generate HTML markup. The should not be used to read Excel files and write to databases. Read http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files – JB Nizet Jan 21 '12 at 10:01

1 Answers1

2
    public  void readExcelFile(InputStream file) {

            try {
                    POIFSFileSystem myFileSystem = new POIFSFileSystem(file);

                    HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

                    HSSFSheet mySheet = myWorkBook.getSheetAt(0);

                    Iterator rowIter = mySheet.rowIterator();
                    rowIter.next();

                    while (rowIter.hasNext()) {
                            HSSFRow myRow = (HSSFRow) rowIter.next();
                            Iterator cellIter = myRow.cellIterator();
                            cellIter.next();
                            System.out.println(((HSSFCell)cellIter.next()).toString());
                      }
Ramesh Kotha
  • 8,266
  • 17
  • 66
  • 90