Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying all the tables from a database

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to display all the tables from a particular database in a screen.I tried like the following to do this

But i dont know how to print the tables in the screen.If i give like

Nothing is printed.Please help me to do this

Thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preethi,
"show tables' is a database specific command. This is ok; it just means you'll need to look up what it returns in your database. My guess is a table consisting of one column containing the table names. If this is the case, you'll want to use out.print(rs.getString(1)) ;
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to be DB independent, rather use the DatabaseMetaData API. The DatabaseMetaData#getCatalogs() returns all catalog names in a ResultSet and DatabaseMetaData#getTables() returns all table names for the given catalog and other patterns. The column names are already described in the API document. Go read it. You can get the DatabaseMetaData by Connection#getMetaData().
[ December 19, 2008: Message edited by: Bauke Scholtz ]
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,thank you all for your replies.
I need to retrieve all the datas in a field in a single combobox.I tried the following .But It displays every combobox for every data because of using while(rs.next())

How can i get all the datas in a single combobox?
please help me to solve this.
[ December 21, 2008: Message edited by: preethi Ayyappan ]
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rearrange your logic. You're now printing a new table row with a new dropdown with only one option for every row from the database. Think smart.

That said, you shouldn't be mingling presentation logic with data access logic. Just map the resultset to a collection of the desired objects and pass it through to JSP where you use JSTL's c:forEach like the following:

[ December 22, 2008: Message edited by: Bauke Scholtz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic