Using Variables In An SQL Statement
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ian_Hendry
Posted On:   Thursday, April 4, 2002 07:21 AM

I am having problems using a variable in an SQL query:- CODE IS BELOW:- String query = "SELECT Characteristic.Description, " + "Customer.firstname, Customer.surname " + "FROM Customer INNER JOIN (Characteristic " + "INNER JOIN CustomerCharacteristic ON " + "Characteristic.CharacteristicCode = " + "CustomerCharacteristic.characteristiccode) " + "ON Customer.customernumber = " + "CustomerCharacteristic.customernumber " + "WHERE (Customer.customernumber=customerNo)"; I have declared the customerNo variable and assigned a value t   More>>

I am having problems using a variable in an SQL query:-

CODE IS BELOW:-



String query = "SELECT Characteristic.Description, " +

"Customer.firstname, Customer.surname " +

"FROM Customer INNER JOIN (Characteristic " +

"INNER JOIN CustomerCharacteristic ON " +

"Characteristic.CharacteristicCode = " +

"CustomerCharacteristic.characteristiccode) " +

"ON Customer.customernumber = " +
"CustomerCharacteristic.customernumber " +

"WHERE (Customer.customernumber=customerNo)";



I have declared the customerNo variable and assigned a value to it (which is available in the database)
but it comes up with a runtime error when I try and run
the code. Is there a way of executing a select statement based on the contents of a variable?



The search works fine when I place the value of the variable into the code, for example,



WHERE (Customer.customernumber=123456789);



but not when I use a variable.



I would appreciate any help that is given.

   <<Less

Re: Using Variables In An SQL Statement

Posted By:   Anonymous  
Posted On:   Thursday, April 4, 2002 07:26 AM

Hihi! Nice!

Try "WHERE Customer.customernumber=" + customerNo or use a PreparedStatement with "WHERE Customer.customernumber=?" and set the value with the set... or PreparedStatement.
About | Sitemap | Contact