If any of the Items value is '1' FLAG SHOULD be set as 'Y'

     for(int k=0;k<itemsList.size();k++)
                        {
                              EmpItems empItems = (EmpItems) itemsList.get(k);
                              pstmt3.setString(1, empItems.getItemId());              
                                          
                              
                              ResultSet rs1= pstmt3.executeQuery() ;
                              while(rs1.next())
                              {
                              
                                    If any of the Items value is '1' FLAG SHOULD be set as 'Y'
                                    
                              }
                                    
                        }
LVL 20
chaitu chaituAsked:
Who is Participating?
 
raj3060Connect With a Mentor Commented:
BTW:

This should be iterating through all the fields:
                                  if( "1".equals(rs.getString(1)) ){
                                      continueFlag = true;                                      
                                  }
i.e.

int numOfColumns = # of Columns;
 for(int i = 1; i <= numOfColumns; i++)
{
           if( "1".equals(rs.getString(i)) ){
                        continueFlag = true;                                      
           }
}



0
 
mkatmonkeyCommented:
If "FLAG" is a field in your database, you should consider doing this task in an sql update statement.
0
 
chaitu chaituAuthor Commented:
"FLAG" is NOT a field in database
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mkatmonkeyCommented:
Assuming that there's only one column in your result set:
//Code for " '1' FLAG SHOULD be set as 'Y'"
if( "1".equals(rs.getString(1)) ){
   FLAG="Y";
}
0
 
chaitu chaituAuthor Commented:
rs.getString(1) should come either 0 or 1;if any of the item VALUE is 1 then it should be 'Y' so we should iterate all items;;
0
 
mkatmonkeyCommented:
I'm not sure what your asking. If you wanted to break the while loop if you find "Y" in your result set, just  use the break statement.

//Code for " '1' FLAG SHOULD be set as 'Y'"
if( "1".equals(rs.getString(1)) ){
   FLAG="Y";
   break;
}
0
 
raj3060Commented:
boolena continueFlag = false;      
for(int k=0;k<itemsList.size();k++)
                        {
                              EmpItems empItems = (EmpItems) itemsList.get(k);
                              pstmt3.setString(1, empItems.getItemId());              
                                         
                             
                              ResultSet rs1= pstmt3.executeQuery() ;
                              while(rs1.next())
                              {
                             
                                  if( "1".equals(rs.getString(1)) ){
                                      continueFlag = true;                                      
                                  }                                    
                              }
                                    if(!continueFlag)
                                        break;
                        }
0
 
raj3060Commented:
Never mind:
>>rs.getString(1) should come either 0 or 1;if any of the item VALUE is 1 then it should be 'Y' so we should iterate all items

Didn't see that.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.