Mahad Rafique
Mahad Rafique

Reputation: 3

AutorowSorter in Jtable linked to mysql

I am trying to populate a jtable from Mysql through defaultTableModel. I get the data and show in jTable, I delete and update the rows from jTable and they get deleted and updated in Mysql.

Now I need to implement sorting and filtering. For sorting I used setautoCreateRowSorter, it works on the jTable but it delete different recoreds from Mysql.

I tried to use convertRowIndexToModel in hope that it might resolve the problem but it didn't. It didn't give any error but didn't resolve the issue.

Now kindly help me to do something so when I delete or update my selected row in jTable, it should delete or update the corresponding row in Mysql.

thanks..

Upvotes: 0

Views: 59

Answers (1)

camickr
camickr

Reputation: 324118

setautoCreateRowSorter, it works on the jTable but it delete different recoreds from Mysql. I tried to use convertRowIndexToModel in hope that it might resolve the problem but it didn't. It didn't give any error but didn't resolve the issue.

To remove a row from the model you would need to use the convertRowIndexToModel() so you delete the proper row in the model.

To remove the row from the database you use the data from the table because all the data is in the view of the table. So you just use the row index without any conversion. That means you use table.getValueAt(...) to get the data for the row to be deleted.

It is then up to you to create the proper SQL delete command. We don't know the structure of your database so we can't tell you what the SQL should be. That is we don't know what the key to your table is or what column in the table represents that key.

Upvotes: 3

Related Questions