This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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.
Thanks in advance.
Jeanne Boyarsky wrote:Are you passing "'DC', 'AL" as a single setString() in JDBC? If so, that doesn't work.
Thanks for your reply.
If you have any idea then please suggest me that How I should frame my query so that it will fulfill my requirement.
Any reason why JDBC is not understanding parameters inside IN keyword when it is in the correct format, that is, IN ('DC', 'AL')
I don't understand your answer so I'm going to repeat my post more descripively. Are you doing something like this:
If so, you need to change your code to use a loop to generate multiple ? binding variables one per value you wish to insert. In particular, use a loop to generate the SQL with more ? and another loop to call setString() multiple times.
If this is not the problem, please show a little more code.