Executing query from java program
I am frustrated with a problem. I have created so many queries for DB2 and successfully executed it.
I am facing problem a query which uses IN keyword.
I have a text box on page where user can enter any number of comma separated values. I need to query DB using this parameter as
SELECT * FROM STATE WHERE STATE_ABBREVIATION IN (:stateAbb);
Here, stateAbb value I will pass from my java program.
Lets say user has entered in text box two values - DC, AL.
In my java program I am taking these values one by one and making it as 'DC' and 'AL' and again appending these as 'DC', 'AL' because in query it must be in single quotes.
So, my query became (printed in console):
SELECT * FROM STATE WHERE STATE_ABBREVIATION IN ('DC', 'AL');
Now, when I send it and execute this, I get the following error :
nested exception is java.sql.SQLException: An undefined column name was detected
The same query when I run directly on sql page ..it runs successfully.
Kindly help me as I am not understanding where things are wrong and I tried almost every option.
Re: Executing query from java program