0

1)How to develop an software which transfer all the data in excel to oracle database?

2) Cells in the excel sheet may vary according to the input given by the user so we have to read the excel dynamically and create a staging table according to the column values?

kindly suggest me an idea how to do it and if possible suggest me a sample link

thanks in advance

Read the filename using the browse 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(); 

Reading the given excel file

        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; }
                     */
                }
            }

apart from this i need to do the same process in a dynamic way where in the above case i have pre-defined the column but i need to write a code where the i should generate a table according to the no of column that is der in the database

1
  • Apache POI library is a good place to start Commented Apr 13, 2015 at 13:50

1 Answer 1

1

One possible way is to use Apache Poi to read the excel sheet row by row.

Once you get the data, you can use populate the data into the database using JDBC drivers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.