简体   繁体   中英

Update changes made to model Element(jlist) to mysql database, issue

please keep in mind i am an amateur. for some reason the code only works if there are only more then one elements in the jlist USING NETBEANS the error is somewhere in generated code.

this is the error i get :

java.lang.ArrayIndexOutOfBoundsException: 1 >= 1

// this is my save button, the problem is when i try to save // voor ledenlijst

private String input ;
Mainn main;
DefaultListModel model = new DefaultListModel();
int selectie;

 private void opslaanActionPerformed(java.awt.event.ActionEvent evt) {                                        
        String leiderString = leider.getText();
        String namen = model.get(1).toString();
        String codev = code.getText();
        String naam1 = model.get(selectie).toString();


        main = new Mainn();
        try {

            //voor leider wijzigen
            main.stat = main.con.prepareStatement("UPDATE project SET leider=? WHERE code = ?");
            main.stat.setString(1, leiderString);
            main.stat.setString(2, codev);


            // voor ledenlijst PROBLEM IS HERE
            main.stat2 = main.con.prepareStatement("UPDATE leden SET naam = ? WHERE naam = ?");
            main.stat2.setString(1, input);
            main.stat2.setString(2, naam1);




            main.stat.execute();
             main.stat2.execute();
            JOptionPane.showMessageDialog(null, "opgeslagen");
        } catch (SQLException ex) {
            System.out.println(ex);


        }


    }  

// below is the code where the changes are made:

private void wijzigActionPerformed(java.awt.event.ActionEvent evt) {                                       
    //try {
    // } catch (SQLException ex) {
    //    System.out.println(ex);
    // }
    //  

  selectie = uitvoerLeden.getSelectedIndex();
  input = JOptionPane.showInputDialog("Wijzig dit project lid", model.elementAt(selectie));
  model.setElementAt(input,selectie);  
}                                      

At what point is model being initialized? I guess it's not before executing this line, where the error is probably occuring.

 String namen = model.get(1).toString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM