File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Populating an HTML option list from a resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Populating an HTML option list from a resultset" Watch "Populating an HTML option list from a resultset" New topic

Populating an HTML option list from a resultset

Kevin Currie

Joined: Feb 02, 2004
Posts: 2
Anyone know how to populate an HTML form option list from a JDBC resultset?
Thanks in advance.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Here's my version of the 2,679 ways this could be done: (in other words, here's how I'd do it):
1) The controller servlet for the request would interact with a model-level class that abstracts the list. Returned would be an array list or other structure containing the name-value pairs for the options list. The JDBC is completely performed in the model class.
2) The controller would place this list on the request as an attribute, then forward to the JSP page for the view.
3) The JSP page would use the JSTL forEach tag to iterate over the list and construct the HTML for the options.
Notice that each tier of the MVC architecural patterm comes into play.
[ February 16, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
One of several FormattedDataSet signatures available. Others take ResultSet's and display multiselect, and regular listboxes. - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
I agree. Here's the link:
subject: Populating an HTML option list from a resultset
It's not a secret anymore!