File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Present Database Field LIst Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Present Database Field LIst" Watch "Present Database Field LIst" New topic
Author

Present Database Field LIst

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
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.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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


Dave
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
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
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
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.
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
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.


Shawn Bayern<br />"JSTL in Action" <a href="http://www.jstlbook.com" target="_blank" rel="nofollow">http://www.jstlbook.com</a>
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
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
Justin F
Greenhorn

Joined: Jul 23, 2002
Posts: 4
A good book that incorporates mySQL and JSP/Beans is "MySQL and JSP Web Applications" by James Turner
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1083
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Present Database Field LIst