This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Show only one record instead of specific record when onclick

 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, i am facing a huge problem in my update form

Like when I click on 1101, it show the records of 1101 to be updated.
But when I click on 1102, it still show the 1101 record instead of 1102. Which mean whatever product I click on it will still be the same 1101 record
My servlets codes are:



My jsp code is:


My database attribitues are:
ProductId
ProdName
ProdColor
ProdDesc
UnitPrice
Quantity
ProdCatId
UserId
ProductImage

Thanks

I need it urgently.
You guys are a great help to me!
Really





 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34372
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loh,
I don't see a where clause in your JSP. Doesn't that just make it always write out the first record in the database?

As an aside, it's not considered good practice to have JDBC code in a JSP.
 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see i see.
But when I change the statement to :SELECT * FROM products where ProductId = '?' "

The text field will be empty
impt.jpg
[Thumbnail for impt.jpg]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34372
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SELECT * FROM products where ProductId = '?'


I can think of a couple causes:
1) You shouldn't have the single quotes around the '?'. PreparedStatements take care of that for you and it could cause the database confusing.
2) Is there whitespace in the id in the database? If so, you'll need to call trim() in your SQL statement.

Also, does that query return no data for record 1001 as well or just 1002? The answer will narrow down the field of problems a bit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic