www.webdeveloper.com
Results 1 to 3 of 3

Thread: SQL Query not working

  1. #1
    Join Date
    Apr 2005
    Posts
    15

    Question SQL Query not working

    Can anyone see anything wrong with this statement ?

    ResultSet res = statement.executeQuery(
    "SELECT * "
    + "FROM CAPS_PARTICIPATION_ACTIVITY WHERE EMP_ID = '"
    + sEmp_id + "AND PRTPT_ACTV_ID =" + code_array[0] +
    "AND ACTV_DT =" + date_range_array[0] + "'");

    It returns 0 records, even though I know there are records matching this criteria. If I run the QUERY one criteria at a time, (say EMP_ID = sEmp_id, or ACTV_DT = date_range_array[0]), it finds the records, but not when I string them together in a compound statement.

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    ResultSet res = statement.executeQuery(
    "SELECT * "
    + "FROM CAPS_PARTICIPATION_ACTIVITY WHERE EMP_ID = '"
    + sEmp_id + "' AND PRTPT_ACTV_ID =" + code_array[0] +
    "AND ACTV_DT ='" + date_range_array[0] + "'");

    There are couple places where you have missed a single qoute, I have addedd them in red color. You have to make sure that your does conform to standard SQL.
    Here is a tip for rest of your SQL life,

    always write your query in note page replace java variables with some test values and run query directly on your db whichever it may be(if oracle then run it using sqlplus tool or sql worksheet tool).
    Once the query is validate like that then just replace the value parts with your variables.
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Apr 2005
    Posts
    15

    Thumbs up

    Thanks a bunch ! I knew those stupid quotes were getting me. I'll look into using a tool like you suggested from now on. Thanks for the info.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles