0

I'm trying to execute a query and store the result in the result set named 'objRs'. In evaluating an if statement, 'objRs' is evaluated as 'true', and the code withing if the if block gets executed. But in the statement below it, 'objRs' is coming as 'false'.

See the below code for a clearer picture:

 if (objRs!= null && objRs.next()) //the statements in this block is                 //executed
   {
                        user_Name = objRs.getString("login_name");
                        user_id = objRs.getString("user_id");
                        corp_id = objRs.getString("corp_id");
                        corp_grp_id = objRs.getString("corporate_group");
                        f_name = objRs.getString("first_name");
                        l_name = objRs.getString("last_name");
                        moNumber = objRs.getString("cont_mobile");
                        gender = objRs.getString("gender");
                        address = objRs.getString("address");
                        city = objRs.getString("b_adr1_city");
                        state = objRs.getString("b_adr1_state");
                        country = objRs.getString("b_adr1_country");
                    }                                  
                }   

                @SuppressWarnings("unused")
                Boolean test = objRs.next();  //the value of test is showing //as 'false' while debugging.

The above code is part of a 'try' block.

Please suggest a solution such that the 'objRs' doesn't become 'false' in the above case.

Lemmy
  • 223
  • 2
  • 12

2 Answers2

0

As per ResultSet.next() each call to this method moves to the next record in the result set until false is returned indicating that there are no more results.

Moves the cursor froward one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
0

If you want to test var have value of your objRs.next() call in if just do the following

Boolean test;
if (objRs!= null && test=objRs.next())
{
  ...
}   
aleksei
  • 315
  • 4
  • 14