Solved

retrieve data to combo box

Posted on 2003-11-28
7
355 Views
Last Modified: 2010-04-01
I manage to retrieve information from my table.

while (rs.next()) {
      out.println("Division");
}

But i have no idea how can i put it (Division) into my HTML code with <select></select> statement, how you will do that?

<select>
    <option value="DD">DD</option>
    <option value="CC">CC</option>    
    <option value="BB">BB</option>    
    <option value="AA">AA</option>
    <option value="FF">FF</option>
</select>

tried this already..not sure is it correct....,and doesnt look neat.

<select>
    <% while (rs.next()) { %>
     <option value="<%= rs.getString("Division") %>"> <%= rs.getString("Division") %> </option>
<% } %>
</select>

any other alternative?
0
Comment
Question by:kotakinabalu
  • 5
  • 2
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9841532
> and doesnt look neat.

jsp rarely does :)

what u have looks fine.
0
 
LVL 92

Expert Comment

by:objects
ID: 9841534
to make it neat you'd need to use a custom tag that knew how to generate your select from a result set.
0
 
LVL 92

Expert Comment

by:objects
ID: 9841540
the only change I'd make would be:

<select>
<%
while (rs.next())
{
   String div =   rs.getString("Division");
%>
     <option value="<%= div %>"> <%= div %> </option>
<% } %>
</select>
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:kotakinabalu
ID: 9841681
Yes, this code is working.
<select>
<%
while (rs.next())
{
  String div =   rs.getString("Division");
%>
    <option value="<%= div %>"> <%= div %> </option>
<% } %>
</select>

And i have change to taht as well. :-)

object, can share with me what i need to do if there is a duplicate data in my table and i don't want to retrieve them more than 1 time.

Division:
FF
AA
FF
CC
FF
BB
AA
FF
FF
DD
BB
DD
DD
DD

what will be my code can be?
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 9841688
You can achieve that by changing the sql query I think so it only returns unique entries. eg.

select distinct Division from mytable
0
 

Author Comment

by:kotakinabalu
ID: 9841791
TQ object...
0
 
LVL 92

Expert Comment

by:objects
ID: 9843383
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lamba in java 8 9 248
spring dependency injection using java config 2 89
SimpleDateFormat.parse examples 19 99
jdbc error in jsp application 20 63
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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