Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update the whole info in database instead of one.

 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I have a problem regarding on updating in database using jsp and servlets.

The problem is when I update it will update the whole records instead on the specific records I choose to update. Like I update yellow beanie color from "green to yellow".
It update all the color to be the same one as well as other details

do you know what happen?

This is my code in servlet:



This is my update form in jsp using dojox



Thanks for your help in all this while.

I really appreciate it
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is the primary key for the table you are updating ?

is it UserId or ProductId ?

Since you are saying that update is working, so, it seems to be a problem with the query.



 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh the primary key is ProductId
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Change your query to



If you want to update products based on userid then


This will solve your issue..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask JDBC questions in the JDBC forum. I have moved this post there for you.
 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

Howerver there seems to be error. It explains that :Syntax error on token(s), misplaced construct(s)
, when I debug

Is there anything wrong with this?



Thanks for your help all this while
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loh,
The prepared statement code looks fine. It's much more likely the error is in your SQL string. Can you post the updated one you are using?
 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah sure

This is the one i am currently using




Is this the correct statement that allows me to update all value regarding on product except UserId
However when I update it will show something Syntax error on token(s), misplaced construct(s) when I debug
Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. The SQL looks right. You might try moving the "set" for parameter 8 to the end. There's no rule that says they have to be set in order, but you never know.

As far as debugging goes, does it work if you just update one column? Two columns? etc. Finding the smallest statement that gives the error will help in narrowing it down.
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you have to remove the 'space' inside your PreparedStatement..

please try this Statement..


Correct me if im wrong..

Hope this help..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic