princehyderabad
asked on
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>"+procR esult.getS tring(1)+" </option>" );
}
MY above code displaying
ABC
ABC
XYX
XYX
I want it to be
ABC
XYX
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>"+procR
}
MY above code displaying
ABC
ABC
XYX
XYX
I want it to be
ABC
XYX
put all the results that in to set object which wont allow duplicates and then print the set
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
if contains is true then you wont display
if it is not true then you will display ans add to the set
ASKER
CAn you help to write it down that line please..
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>"+procR esult.getS tring(1)+" </option>" );
s.add(name);
}
}
Set s = new HashSet();
ResultSet rs= cs.executeQuery();
while(rs.next())
{
String name = procResult.getString(1);
if(!s.contains(name)){
out.print("<option>"+procR
s.add(name);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cool Thanks !!
ASKER
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
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
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
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
ASKER
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
https://www.experts-exchange.com/questions/21398080/Dropdown-problem.html
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
https://www.experts-exchange.com/questions/21398080/Dropdown-problem.html