This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SQL error

 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks! I'm having a bit of trouble getting a SELECT SQL query to work. I'm not sure what's wrong with it as it should work. I pass a parameter which is the ID of a customer and this ID should then be used to select appopriate fields from the CUSTOMER table for that particular record. Here is the query -

The problem I have is that I usually specify the WHERE part as

But when I do this the query does not execute at all. But the above way, ALL of the records from the table are displayed, despite sending a specific ID.
Can anyone help??
Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to use the PreparedStatement class. You give this class your SQL quey with the variables represented as "?" marks. Then you use the setXXX methods to specify the values of the variables before issuing the query. The PreparedStatement takes care of all the quoting and escaping that might need to be done.
 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sheriff, I think I'll use prepared statements all the time now!
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!