Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Proper Display using DB

hi,

Currently I'm using this code and getting values. But it is duplicating...
DB Table:
Family     Version
ABC          1.2
ABC          2.5
XYX         9.0
XYX         10.1

ResultSet rs= cs.executeQuery();
while(rs.next())
  {
    out.print("<option>"+procResult.getString(1)+"</option>");
   }

MY above code displaying
ABC
ABC
XYX
XYX

I want it to be
ABC
XYX
0
princehyderabad
Asked:
princehyderabad
  • 5
  • 4
1 Solution
 
koppchaCommented:
put all the results that in to set object which wont allow duplicates and then print the set
0
 
koppchaCommented:
or you can use contains(Object o) of set and loop just once
if contains is true then you wont display
if it is not true then you will display ans add to the set
0
 
princehyderabadAuthor Commented:
CAn you help to write it down that line please..
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.

 
koppchaCommented:
import java.util.*;

Set s = new HashSet();
ResultSet rs= cs.executeQuery();
while(rs.next())
  {
   String name = procResult.getString(1);
   if(!s.contains(name)){
    out.print("<option>"+procResult.getString(1)+"</option>");
    s.add(name);
    }
   }
0
 
koppchaCommented:
small correction

import java.util.*;

Set s = new HashSet();
ResultSet rs= cs.executeQuery();
while(rs.next())
  {
   String name = procResult.getString(1);
   if(!s.contains(name)){
    out.print("<option>"+name +"</option>");
    s.add(name);
    }
   }
0
 
princehyderabadAuthor Commented:
Cool Thanks !!
0
 
princehyderabadAuthor Commented:
Need help on this line too please.......

out.print("<option>"+ procResult.getString(1) +"--"+ procResult.getString(2) +"--"+ procResult.getString(4) +"</option>");

Its is display in this way:
BIG -- DNS -- V1.0
BIG -- DNS -- V2.0
BIG -- DNS -- V3.0
ABC -- INS -- V4.5
ABC -- INS -- V5.5
ABC -- INS -- V5.5

How to get the output in this way.
BIG -- DNS -- V1.0
                    V2.0
                    V3.0
ABC -- INS -- V4.5
                    V5.5
                    V5.5
0
 
koppchaCommented:
Hmm  New Question Prince :)
   since it is in one <option> tag you can get what you are looking for but it will be having 6 option lines instead of two
BIG -- DNS -- V1.0
                    V2.0
                    V3.0
ABC -- INS -- V4.5
                    V5.5
                    V5.5
    when you find the similar string you do not print rest of the time you print it.But it is up to you how you want the design to be

 
0
 
princehyderabadAuthor Commented:
well but this are not fixed 6 versions. It depends on DB list. It may more then 10 etc.,
I dont care how the code look, what I want is user select proper 'Family' --> Product --> Version
Dont want user to select wrong family maping to wrong product maping wrong version and vice-versa.

Anywaz I hv already created new thread bcoz its more then this plz hv a look
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21398080.html
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now