Solved

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

Posted on 2013-05-29
10
303 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
  • 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now