wood burning stoves 2.0*
The moose likes JDBC and the fly likes SQL error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL error" Watch "SQL error" New topic

SQL error

shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
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??
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

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.

[Jess in Action][AskingGoodQuestions]
shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
Thanks Sheriff, I think I'll use prepared statements all the time now!
jQuery in Action, 2nd edition
subject: SQL error
Similar Threads
Linking two tables in JDBC
Data type mismatch need to convert string to a number
Help required with DB pagination
JDBC with Oracle prob URGENT
SQL insert query