简体   繁体   English

即使在前面的语句中将true执行为true,resultSet.next()也将变为“ false”

[英]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'. 我正在尝试执行查询并将结果存储在名为“ objRs”的结果集中。 In evaluating an if statement, 'objRs' is evaluated as 'true', and the code withing if the if block gets executed. 在评估if语句时,将'objRs'评估为'true',并且如果执行if块,则代码将失效。 But in the statement below it, 'objRs' is coming as 'false'. 但是在下面的语句中,“ objRs”作为“ 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. 上面的代码是“ try”块的一部分。

Please suggest a solution such that the 'objRs' doesn't become 'false' in the above case. 请提出一种解决方案,以防止上述情况下的'objRs'变为'false'。

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. 根据ResultSet.next() ,对此方法的每次调用都移至结果集中的下一个记录,直到返回false ,表明没有更多结果了。

Moves the cursor froward one row from its current position. 将光标从当前位置向前移动一排。 A ResultSet cursor is initially positioned before the first row; ResultSet游标最初位于第一行之前; 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 如果你想test VAR有你的价值objRs.next()调用if只是做以下

Boolean test;
if (objRs!= null && test=objRs.next())
{
  ...
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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