简体   繁体   中英

resultSet.next() coming 'false' even though it is executed as true in previous statement

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.

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.

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())
{
  ...
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM