Hy , i read all the other posts about this error but didn`t helped me , tried google but notheing.

I have the following method :

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        DefaultTableModel model = (DefaultTableModel)jTable2.getModel();
        int nrrows = jTable2.getSelectedRowCount();
        int[] rows = jTable2.getSelectedRows();
        System.out.println("randuri selectate " +nrrows);
        int j,i;
        int col=0;
        Object value = new Object();
              value = model.getValueAt(rows[i] , col); 
              System.out.print("randul"+rows[i]+" " );
              System.out.print( value);
              System.out.println(" ");
              String connectionURL = "jdbc:mysql://localhost:3306/bazadedate";
              Connection connection;
                  connection = DriverManager.getConnection(connectionURL, "root", "123456");
                  PreparedStatement pst =  connection.prepareStatement("DELETE FROM tabel WHERE id="+value);
                  j = pst.executeUpdate();
              catch(Exception e){
                  System.out.println("The exception is " + e);

And i keeps throwing me the same error :

"AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5 >= 4

The task of the button when it`s clicked is to delete from database the records with the id ... .

loop backwards, currently once you do removeRow(0) the former row 1 becomes row 0, then when you doe removeRow(1) (really row 2 now) the original row 3 becomes row 1, etc, etc.

that right +1

Thanks for hint but I tried that and it keeps giveing me the same error.

Did start at [nrrows] or [nrrows-1]?

Put in a println debug statement just before the line the error occurs on and figure out why it's sending too high an index value.

Edited 5 Years Ago by Ezzaral: n/a

This question has already been answered. Start a new discussion instead.