• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Populate listbox from sql

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I populate a listbox from sql? Thanks.
 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just read data from database and for each record put it html list box syntax as values.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Sheriff
Posts: 67695
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic