aspose file tools*
The moose likes JSP and the fly likes Populate listbox from sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Populate listbox from sql" Watch "Populate listbox from sql" New topic
Author

Populate listbox from sql

Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
How can I populate a listbox from sql? Thanks.
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Just read data from database and for each record put it html list box syntax as values.


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Take a look at the JSTL (Java Standard Tag Library) SQL & Core Taglibs. You'll want to use the <sql:query> tag to query your database, then use the <c:forEach> tag to iterate through the row set, placing the value in your list. You'll also need to create your datasource and JDBC connection in your web application. All this is not something that can be explained in a few sentences. I'd recommend taking a look at one of the many books available on JSTL and/or JavaServer Pages. JavaServer Pages 2nd Edition (for JSP 1.2 & JSLT 1.0) by Hans Bergsten (published by O'Reilly) has a nice chapter on the subject of database access using JSP. The third edition (on JSP 2.0 & JSTL 1.1) was recently published also.
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Mark,

But if this question was asked in the first place, I am not sure if author is familiar with JSTL and learning JSTL just to populate the list is not worth it. Of course it's good for other projects. Just my opinion.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Originally posted by Alex Kravets:
Mark,

But if this question was asked in the first place, I am not sure if author is familiar with JSTL and learning JSTL just to populate the list is not worth it. Of course it's good for other projects. Just my opinion.


Some valid points Alex. I guess I was just in auto response mode and replied with what I felt was the best way of doing it, failing to stop and consider the author's current skill set. My bad.

(BTW, your reply was not present when I started to type my reply. I would not want you to think I was attempting to imply your reply was incomplete or inaccurate).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

But there's nothing wrong with nudging them in the right direction either. "Current skillset" should never be a static set.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Of course not. But I see all these technologies as a way to simlify readability/usability of your code and not learning the workings behind it.
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Mark,

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populate listbox from sql