0

A have a jtable which shows the records from database. it's boind elements from database

i want to add new artist. i press insert i this form and create a new form where i input the artist data whith the following code

    private void but_saveActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {                                         
        Artist a1=new Artist();

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("musicstationPU");
        ArtistJpaController ajc1=new ArtistJpaController(emf);


        a1.setMusicgenregenreId((Musicgenre)  cb_genre.getSelectedItem());



        a1.setFirstname(tx_name.getText());
        a1.setLastname(tx_lastname.getText());
        a1.setArtistname(tx_artistname.getText());
        a1.setSex(cb_sex.getSelectedItem().toString());

        Date date = null;
        try {
            date = new SimpleDateFormat("MM-dd-yyyy").parse(tx_birthday.getText());
        } catch (ParseException ex) {
            Logger.getLogger(ArtistNew.class.getName()).log(Level.SEVERE, null, ex);
            lab_datevalid.setText("Please enter a valid date/MM-DD-YYYY/");
        }
        a1.setBirthday(date);
        a1.setBirthplace(tx_birthplace.getText());



        ajc1.create(a1);


        ArtistManage am1=new ArtistManage();
        am1.setVisible(true);
        dispose();
    } catch (Exception ex) {
        Logger.getLogger(ArtistNew.class.getName()).log(Level.SEVERE, null, ex);

    }

}         

No i want to edit some artist when i click selected row from jtable or delete the artist from the selected row and simultaneously update the database

The problem is that I don't know how to use the Jtanle to delete a record from jtable and database.

I used defaultTableModel but it throws exception due to the table is bond elements.

palios7
  • 15
  • 3

0 Answers0