Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Oct 12, 2022 1:07 pm

Dear Support!

I have a Exception in DataTable.
I will excel to DataBase import, but i have java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 16
I write in code who is the Exception.
My code:
Code: Select all
void feltolt()
   {
       Connection conn = null;
        Statement stmt = null;
        try
        {
           try
           {
              Class.forName("com.mysql.cj.jdbc.Driver");                                //Driver meghívása
           }
           catch (Exception e)
           {
              System.out.println(e);
              String hibauzenet2 = e.toString();
              JOptionPane.showMessageDialog(null, hibauzenet2, "Hiba üzenet", 2);
           }
           
        conn = DriverManager.getConnection("jdbc:mysql://172.20.22.29", "veasquality", "kg6T$kd14TWbs9&gd");                           //kapcsolat létrehozása
        stmt = conn.createStatement();                                                                                                  //csatlakozás
       
        PreparedStatement statement = conn.prepareStatement("INSERT INTO qualitydb.Gyartasi_adatok (ID, VT_azon, Cikkszam, Vevo, Vevoi_megnev, Datum, Muszak, Ellenor_neve, Hibagyujtes_helye,"
                + "Felajanlott, Minta_nagysag, PCB_sorszam, Hibakod, Hiba_megnevezes, Pozicio, Hibak_szam, Sor) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
       
        Workbook workbook = new Workbook();
        workbook.loadFromFile("c:\\Users\\kovacs.zoltan\\Desktop\\Mappák\\Java projekt\\minden.xlsx");
        Worksheet sheet = workbook.getWorksheets().get(0);

        DataTable dataTable = sheet.exportDataTable();           //  <== Here is the Exception

        for (int i = 0; i < dataTable.getRows().size(); i++)
        {
            for (int j = 0; j < dataTable.getColumns().size(); j++)
            {
                statement.setString(j + 1, dataTable.getRows().get(i).getString(j));
            }
            statement.executeUpdate();
        }
        statement.close();
        conn.close();
                                                                                                                 
        }
        catch (SQLException e1)                                                     //kivétel esetén történik
        {
           e1.printStackTrace();
           String hibauzenet2 = e1.toString();
           JOptionPane.showMessageDialog(null, hibauzenet2 + "\n \n A Mentés sikertelen!!", "Hiba üzenet", 2);
        }
        catch (Exception e)
        {
           e.printStackTrace();
           String hibauzenet2 = e.toString();
           JOptionPane.showMessageDialog(null, hibauzenet2, "Hiba üzenet", 2);
        }
        finally                                                                     //finally rész mindenképpen lefut, hogy hiba esetén is lezárja a kacsolatot
        {
           try
           {
              if (stmt != null)
                 conn.close();
           }
           catch (SQLException se) {}
           try
           {
              if (conn != null)
                 conn.close();
           }
           catch (SQLException se)
           {
              se.printStackTrace();
           } 
        }
        System.out.println("Minden kész!");
   }


What make i wrong?

Vizinyenyec
 
Posts: 15
Joined: Mon May 09, 2022 10:16 am

Thu Oct 13, 2022 10:32 am

Hello,

Thanks for your inquiry.
To help us reproduce your issue and work out a solution for you. Please offer the following messages, thanks for your assistance in advance.
1) Your input excel file.
2) Your Jdk version, such as Oracle Jdk1.8.
3) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 927
Joined: Tue Mar 08, 2022 2:02 am

Thu Oct 13, 2022 12:03 pm

Hallo Abel,

I have send an email to Jack mit requiremed info.

Best Regards
Vizinyenyec

Vizinyenyec
 
Posts: 15
Joined: Mon May 09, 2022 10:16 am

Fri Oct 14, 2022 10:05 am

Hello,

Thanks for your feedback.
After investigation, I reproduced your issue and logged it into our bug tracking system with the ticket number SPIREXLS-4192. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 927
Joined: Tue Mar 08, 2022 2:02 am

Fri Oct 14, 2022 10:39 am

Hello

Thank you for the answer.
I waiting for fix it.
Thank's for helping.

Best Regards
Vizinyenyec

Vizinyenyec
 
Posts: 15
Joined: Mon May 09, 2022 10:16 am

Mon Oct 17, 2022 1:52 am

Hello Vizinyenyec,

Once there are any updates, I'll inform you in time.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 927
Joined: Tue Mar 08, 2022 2:02 am

Fri Oct 21, 2022 10:03 am

Hello,

Greeting from E-iceblue.
For the issue with the number SPIREXLS-4192, I have some updates to inform you:

When you export data using the exportDataTable() method with no parameters, the first row of the table in the excel document will be the default column name, and duplicate column names are not allowed in a table, otherwise, an exception will be thrown. For the excel files including the table without column name, you need to use the following code to export data.


Code: Select all
DataTable dataTable = sheet.exportDataTable(sheet.getAllocatedRange(), false, false);   


The first parameter specifies the range, the second parameter determines whether to export the first row of the table as column name, and the third parameter determines whether to evaluate the formula value.
If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 927
Joined: Tue Mar 08, 2022 2:02 am

Mon Oct 24, 2022 8:37 am

Hello,

Thank you for the feedback.
It works fine!
You are great!!
Thank you everything!

Best Regards

Vizinyenyec
 
Posts: 15
Joined: Mon May 09, 2022 10:16 am

Mon Oct 24, 2022 8:53 am

Hello,

Thanks for your feedback.
If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 927
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.XLS