• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Present Database Field LIst

 
Bartender
Posts: 1938
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to generate a SQL statement based on a table name the user enters.
Here's the scenerio:
====================
A user enters a table name into a JSP page TEXT field.
I now want to populate a list (combo or whatever) with all the fields in a database table (returned from a RecordSet or Columns object) based on this entered table name -- so the user can pick only the fields he wants.
Then, using this list, I could include the fields the user selected in the dynamically generated SQL statement (that is, I'd process the list and generated the SQL necessary).
(I understand the SQL part, the problem I'm having is building the GUI to get the field list)
Is what I'm describing (the generating a pick list from a database table name) HTML or JSP or Javascript or something else?
Can anybody recommend a good book that shows this technique?
Thanks much in advance.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike
Sounds more like a JDBC/servlet question. To get the field names of a table you'll use the metadata from the ResultSet then just loop through them and create an HTML select item in the Response. You could even create a bean that creates it and returns it to you. The list creation has to be done server side before the response is sent to the client because you can't communicate back and forth to try to use javascript to build the list - doing it in the servlet or with a bean in a JSP is much easier too

hope that helps
 
Mike London
Bartender
Posts: 1938
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Coincidentally, I'm actually using a bean now for most of the work, but I don't know how to create, interactively, an HTML control and then process it inside the bean.
I have the "Core/More" books for Servlets, but aside from the HTML forms chapter, which doesn't go into detail on this, I don't see anything that can help.
Do you have any suggestions for a good book that details how to do what you're suggesting?
Thanks.
 
Mike London
Bartender
Posts: 1938
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention in my last reply that I understand the meta data stuff and database stuff too.
What I'm missing is building the HTML or other lists/controls to display the fields (in my bean) at runtime and getting interactive user input.

Thanks.
 
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike London:
I forgot to mention in my last reply that I understand the meta data stuff and database stuff too.
What I'm missing is building the HTML or other lists/controls to display the fields (in my bean) at runtime and getting interactive user input.

Thanks.


A few thoughts. First, I think you're looking for an HTML <select multiple="multiple"> form field, but I can't tell if that's exactly what you want.
Separately, since you're producing the HTML dynamically, you might want to look at JSTL. Using JSTL to produce a form is more elegant than producing HTML from within a JavaBean; it lets you write and change HTML without having to embed it in Java code. JSTL also has SQL-access tags, but you don't have to use those to generate a form dynamically. My book "JSTL in Action" covers this use of JSTL (to generate and read forms) in detail.
 
Mike London
Bartender
Posts: 1938
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for this great reply.
Your book sounds great.
Can you also recommend a good companion book that discusses how to incorporate HTML forms inside beans?
Or, would I just get any good HTML reference book and adapt it to create the necessary HTML inside a bean?
What I'm worried about is that a regular HTML book might not have the build-on-the-fly (in a loop) examples I really am looking for.
Look forward to your reply.
-- Mike
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good book that incorporates mySQL and JSP/Beans is "MySQL and JSP Web Applications" by James Turner
 
Mike London
Bartender
Posts: 1938
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic