Reputation: 23
I need to delete the specific row from database as displayed in jtable. I want to add action listener on the delete button. But I am kind of new to java programming so facing problems.
My table code is as follow...
rt= st.executeQuery("SELECT * FROM login");
DefaultTableModel model=(DefaultTableModel) usertable.getModel();
while(rt.next()){
username = rt.getString(2);
firstname = rt.getString(5);
lastname = rt.getString(6);
emailid = rt.getString(1);
accounttype = rt.getString(4);
model.addRow(new Object[] {username, firstname, lastname, emailid, accounttype});
Upvotes: 0
Views: 916
Reputation: 285405
Deleting from the JTable really means deleting from the table's TableModel. If you've created the model yourself, then your model will likely have the method to do this, and the method would then call a fire notification method, here fireTableRowsDeleted(...)
inherited from the AbstractTableModel parent. If you did not create a model, then likely you're using a DefaultTableModel and would call its removeRow(...)
method.
As for the database, you would create and execute a PreparedStatement that has a DELETE command in it, and the details of which will depend on your database and your code.
Upvotes: 1