This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Editable jtable  RSS feed

 
Bryan van Ritter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am trying to update my database from an editable jtable. i've searched the web and came up with the example below which i changed.
now i do not know if this is the correct approach. also i am trying to execute the code on press of a button:





kind regards,
bryan

 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "row" should also be part of your PreparedStaement:







Then that code should be in the ActionListener, not the TableModelListener.

If you automatically update the row when the data changes then there is no need for a button because the data has already been updated.

You would either use the TableModelListener or the ActionListener of a JButton, but not both.

But if for some reason you want the code in both places, then just create a method to update the data. Then you can invoke the method from both listeners.
 
Bryan van Ritter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i tried what you've mentioned, but the add for the row give an index out of bound. code is now as below and after edit the database is not being updated.

 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried what you've mentioned


You didn't change the SQL statement as I suggested.

but the add for the row give an index out of bound


What "add". You are trying to update the database.

You need to do your own problem solving. I don't have access to your database. I don't know why you get an index out of bounds. Did you print the value?
 
Bryan van Ritter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the reply. i will do my own problem solving.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!