• Post Reply Bookmark Topic Watch Topic
  • New Topic

Update Jtable doesn`t work  RSS feed

 
Gabriel Turmic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Can anyone tell me why this statement does not update my entry?


Insert and delete works fine but update one doesn't execute.





 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you get an error for the update?
 
Gabriel Turmic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No error
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your update sql, you had the id field in the set and where clause

update mytable set id=1 where id=1

Shouldn't it be like

update mytable set id=<newid> where id=<oldid>

Your idtext.getText() is getting the old or new id? Where is the other id?
 
Dave Tolls
Rancher
Posts: 2914
36
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really ought to be using PreparedStatements rather than concatenating your SQL together like that.
It's prone to errors.
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know it does not execute?

If you want to continue using your approach of building a String, then do it outside the SQL call, and put a println statement in your code so you can actually see the SQL statement you have built.

Gabriel Tgabriel wrote:No error
 
Gabriel Turmic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made some changes and it's work fine now. Thank you.


How can I generate automatically an unique Id?

Edit: Solved with UUID.randomUUID().
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!