java - How to save the new values from cells, not the old ones? -


i have jtable in jscrollpane , data comes database. cells editable, , want save new values (the edited ones) in database. problem getvalueat(row, col) returns old, unedited values.

here code takes values cells , insert them in database.

     defaulttablemodel tablemodel = (defaulttablemodel) table.getmodel();     int row = table.geteditingrow();     if(row == -1) return -1;     string name = tablemodel.getvalueat(row, 0).tostring();     string stringprice = tablemodel.getvalueat(row, 1).tostring();     float price = float.parsefloat(stringprice);     products.updateproduct(name, price);     ...     return 1; 

and here in updateproduct(name, price) method:

 update products set `prod_name` = 'old_name', `prod_price` = 'old_price' `id` = 4 

instead of:

 update products set `prod_name` = 'new_name', `prod_price` = 'new_price' `id` = 4 

there might simple solution, can't figure out. appreciated.

without knowing how code snipped invoked guess problem cell editor has not been stopped model has not yet been updated new data.

you can use tablemodellistener notified when data in cell changes. guaranteed data in model correct.

or, if using "save" button update database, need read table stop editing solution problem.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -