Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to find the values from List based on another id ?

Posted on 2013-05-29
10
Medium Priority
?
311 Views
Last Modified: 2013-05-31
Hi,
I have list result set and have to find out the list of values based on another id.
For example : Fields attibutes are:productcode , descr , itemcode..etc
and one productcode has multiple itemcodes so i need to find list of itemcode which assoicated productcode.

Iterator<SearchResult> iterator = partitems.iterator();
while(iterator.hasNext())
{
SearchResult Sr = (SearchResult)iterator.next();
System.out.println(sr.getprdcode());            
}

How to find itemcodes which assoicated product code using same result set ?
or do need to do again query to get the result ?
0
Comment
Question by:Rose_Taylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39205829
You can only extract the details you need out of a query that has been done using a join. From that you need to build a List of beans that itself encapsulates a Collection
0
 

Author Comment

by:Rose_Taylor
ID: 39205934
In my result set i have all the values , but when displaying i need to display one productcode with multiple itemscode.

Example :
productcode : 102
itemcode : 12 , 41 , 52 , 63

These four itemcode associated with productcode 102. These values are same row in the database . I have 1000's of productcode with multiple item codes.When displaying productcode need to display itemcode as well.

Expected output :
product code : 102
itemcode : 12,41,52,63

productcode : 105
itemcode : 11 ,78 , 1 ,7 ,9 ,20

like above...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39206304
You're saying the ResultSet comes out like
102,12,41,52,63

Open in new window

and not like
102,12
102,41
102,52
102,63

Open in new window

?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Rose_Taylor
ID: 39206333
Please find below SQL return values :

product   itemcode  Desc
6799        8205        OR
6799        8206        OR
6799        8208        OR
6799        8422        OR
6799        8424        OR
6799        1381        OR
6799        1485        OR
6799        1563        OR

Expected output :
8205 OR 8206 OR 8208 OR8422 OR as like
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39206352
OK. I would

a. Make a Product bean
b. Make an ItemInfo bean with attributes of at least 'code' and 'description'
c. Give Product a List<ItemInfo>
d. Give it an addItemInfo method
e. Create a Set<Product>

The algo should go something like

a. read the row
b. if Product(id) not in the Set<Product>, create it, else get() it
c. For the rest of the row call
product.addItemInfo(new ItemInfo(rs.getString("itemcode"), rs.getString("description")));

Open in new window

0
 

Author Comment

by:Rose_Taylor
ID: 39206366
Yes, your correct.

using below code , i can able to get all the values.
Iterator<SearchResult> iterator = partitems.iterator();
while(iterator.hasNext())
{
SearchResult Sr = (SearchResult)iterator.next();
sr.getprdcode());            
sr.getitecode();
//how to merge the two fields values in single row as like column3  ?
}


column1   column2    column3  
6799         item1         8205 OR 8206 OR 8208 OR8422
6799         item2         8205 OR 8206 OR 8208 OR8422
6799         item3         8205 OR 8206 OR 8208 OR8422
6799         item4         8205 OR 8206 OR 8208 OR8422
6799         item5         8205 OR 8206 OR 8208 OR8422
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39206966
Sorry - i'm confused - you seem to have repeated the question, which i've answered ...
0
 

Author Comment

by:Rose_Taylor
ID: 39209395
Iterator<Search> iterator = products.iterator();
MultiHashMap lists = new MultiHashMap();
StringBuilder sb = new StringBuilder();
List list = null;

while(iterator.hasNext())
{
    Search req = (Search)iterator.next();
    String product = req.getProduct();
    sb.append(req.getpartitem()); //appending multiple items in the string
    sb.append(" ");
    sb.append(req.getdesc()));
    sb.append(" ");
    lists.put(product, sb.toString());
   sb.setlength(0);
    req.getProduct();
    req.getDescr();
    req.getreqspartno();
    req.getreqproddescr();          
}

Set set = dependencies.entrySet();
Iterator i = set.iterator();

while(i.hasNext())
{
     Map.Entry me = (Map.Entry)i.next();
     list=(List)lists.get(me.getKey());
     for(int j=0;j<list.size();j++)
     {
        list.get(j).toString()));
     }
}

How to split the values ?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1500 total points
ID: 39210026
I think i've now answered this elsewhere
0
 

Author Closing Comment

by:Rose_Taylor
ID: 39211474
Good
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question