• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populate listbox from sql

 
Raj Puri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I populate a listbox from sql? Thanks.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just read data from database and for each record put it html list box syntax as values.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But there's nothing wrong with nudging them in the right direction either. "Current skillset" should never be a static set.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic