Link to home
Start Free TrialLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

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'
                                    
                              }
                                    
                        }
Avatar of mkatmonkey
mkatmonkey
Flag of United States of America image

If "FLAG" is a field in your database, you should consider doing this task in an sql update statement.
Avatar of chaitu chaitu

ASKER

"FLAG" is NOT a field in database
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";
}
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;;
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;
}
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;
                        }
ASKER CERTIFIED SOLUTION
Avatar of raj3060
raj3060
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.