If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Wrong value fetched each time from Result Set

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-04, 08:23
sanjum sanjum is offline
Registered User
 
Join Date: Jan 2004
Posts: 7
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
Reply With Quote
  #2 (permalink)  
Old 02-23-04, 05:23
jsander jsander is offline
Registered User
 
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

Quote:
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On