Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Executing query from java program

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Executing query from java program

    Hi All,

    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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,337
    Thanks
    182
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: Executing query from java program

    This thread has been cross posted here:

    http://www.java-forums.org/advanced-java/45732-executing-query-java-program.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. Executing a program on my computer with an ActionListener?
    By FoxBoiii in forum Java Theory & Questions
    Replies: 1
    Last Post: April 29th, 2011, 05:22 PM
  2. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 10:15 AM
  3. Help Executing C Program From Java! (Ubuntu)
    By penguinGirl in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 18th, 2010, 01:47 PM
  4. Executing Linux Commands with Java GUI
    By linuxrockers in forum AWT / Java Swing
    Replies: 2
    Last Post: February 15th, 2010, 09:57 PM