Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    7

    Unanswered: Wrong value fetched each time from Result Set

    Hi,

    I have a query similar to the one below:

    SELECT 1 AS STRATEGIC_FLAG FROM TBL_A WHERE TBL_A.CODE = ? UNION SELECT 0 AS STRATEGIC_FLAG FROM TBL_B WHERE TBL_B.CODE = ?

    Now, when I put in the inputs and then run the query in command center, I get the values as 1 and 0 in two separate rows as only two records match the condition.

    Now when I use this query in Java, put it as a prepared statement and then get the result set, the result set always gives me 0 for both the rows. Even if both the records match the first condition and an output of 1 is expected, the result set gives 0.

    I am using resultset.getString("STRATEGIC_FLAG")

    When I SOP this, I get 0 for both the records.

    Can anyone suggest as to what the problem is?

    Regards,
    Jumani

  2. #2
    Join Date
    Apr 2003
    Posts
    191

    Re: Wrong value fetched each time from Result Set

    Hi,

    are you positive you are on the same data?

    You should play around a bit with the statement to see exactly which records get selected.

    Strange that this query returns two identical rows from your Java code. The UNION clause suppresses duplicates by default, you would have to explicitly state UNION ALL to allow for duplicates. So this *may* be a driver issue, if your program turns out to be clean of bugs.

    Johann

    Originally posted by sanjum
    Hi,

    I have a query similar to the one below:

    SELECT 1 AS STRATEGIC_FLAG FROM TBL_A WHERE TBL_A.CODE = ? UNION SELECT 0 AS STRATEGIC_FLAG FROM TBL_B WHERE TBL_B.CODE = ?

    Now, when I put in the inputs and then run the query in command center, I get the values as 1 and 0 in two separate rows as only two records match the condition.

    Now when I use this query in Java, put it as a prepared statement and then get the result set, the result set always gives me 0 for both the rows. Even if both the records match the first condition and an output of 1 is expected, the result set gives 0.

    I am using resultset.getString("STRATEGIC_FLAG")

    When I SOP this, I get 0 for both the records.

    Can anyone suggest as to what the problem is?

    Regards,
    Jumani

Posting Permissions

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