Update JTable and Database Values in Java Swing
Update JTable and Database Values in Java Swing:
________________________________________________
1.Code for Update Button
int i = table.getSelectedRow(); DefaultTableModel model = (DefaultTableModel) table.getModel(); if(i>=0){ model.setValueAt(txtFName.getText(), i, 1); model.setValueAt(txtLName.getText(), i, 2); } try{ Class.forName("com.mysql.cj.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/userrdata",
"root", ""); String quey = "UPDATE userrtable SET id=?, fname=?, lname=? WHERE id"; pst = con.prepareStatement(quey); pst.setString(1, txtID.getText()); pst.setString(2, txtFName.getText()); pst.setString(3, txtLName.getText()); pst.executeUpdate(); }catch(SQLException ex){ JOptionPane.showMessageDialog(null, ex); }catch (ClassNotFoundException ex) { Logger.getLogger(AddUpdateDelete.class.getName()).log(Level.SEVERE, null, ex); } txtID.setText(""); txtFName.setText(""); txtLName.setText("");
_____________________________________________
Dark Hers
YouTube
https://instagram.com/darkhers
https://www.facebook.com/darkhers
TikTok
https://www.tiktok.com/@darkhers
https://www.pinterest.co.uk/darkhers
Comments
Post a Comment