Link to home
Start Free TrialLog in
Avatar of NASEEMA
NASEEMA

asked on

Problem while iterate in Two loops

hi all,
         in reference to my earlier post,  your comment "
         Additionally u can pass all ids as a string to the above qery and take the output in a Map and then iterate in a single loop. "
        Can you please let me know how can i do that ?

Awaiting your expert comment...
Avatar of Murali Murugesan
Murali Murugesan
Flag of Australia image

Something like this,

your value in variable tprID and seq_nr should be like this,

tprID : 'MN4676','4567TR','TU36363'
seq_nr: '2','4','6'  -- (i guess values should be unique since sequence number)

public Map getLogCounter(String tprID,String seq_nr) {
                                    Map counterMap = new HashMap();
                                     String sql="SELECT opn_seq_nr,COUNT(*)"
                                                       +" FROM   log"
                                                       +" WHERE  opn_id IN ("+tprID
                                                       +") AND opn_flag ='TPR'"
                                                       +" AND opn_seq_nr IN ("+seq_nr
                                                         +") AND upd_flag  IS NULL GROUP BY opn_seq_nr ";      
                               //PreparedStatement - implement this
                                         //resultset - implement this

                                   while(rs.next()){
                                          counterMap .put(rs.getString(1),rs.getInt(2));
                                    }      
                              return counterMap ;                              
                              }


Map values after iteration should look like below,

2  20
4  60
6  90


Now get the map values and get the count for each sequence number and iterate the second loop.

-Murali*

Avatar of NASEEMA
NASEEMA

ASKER

Hi,
  Sorry for ver late reply.
   seq_nr is not unique. and i feel i couldnt be able to implement code.is  There any other possibilty in achieve my task
 
Avatar of NASEEMA

ASKER

HI All,
        Any other possibility in achieve my task..


is your tprID is unique? If not then replace the select as follows,

SELECT opn_seq_nr || '~' ||opn_id,COUNT(*)

Now a combination of sequence and tprID  will be unique. Now u can implement the above code.

Even if this combination is not unique i would suggest u to use a bean class object (i hope u already have one) as the value and key for the map as some unique running number.

I feel this code would reduce you most of the delay and also we need to see if we can refactor the next loop as well once u implement this.

-Murali*
did u try to implement this function ? or still facing problem in implementing it?
Avatar of NASEEMA

ASKER

Hi,
   i  couldnt be able to implemnt your last input.
  i appreciate if you can write the whole code so that i will copy and paste the code .
  sorry that i am asking u to write the code.

ASKER CERTIFIED SOLUTION
Avatar of Murali Murugesan
Murali Murugesan
Flag of Australia 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
Avatar of NASEEMA

ASKER

HI,
  Thanks a lot for the help.i will accept ur comment .I appreciate if you can let me know the remaining code too....

sorry again to request to write code for me....:
Sorry Naseema, this time you need to give your best try and make up the code on your own.
You do the code and fix the bugs and if you are caught in somewhere we might guide you.

Out of the two for loops i have showed you how to minimize one loop. You get the count from this and iterate the next loop.

Thanx
-Murali*