This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes pulling the table names from a Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "pulling the table names from a Database" Watch "pulling the table names from a Database" New topic
Author

pulling the table names from a Database

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Hi All,
The code below displays 2 comboBoxes and puts the data from each table into the pull downs. How can I get it so that the first comboBox displays all the tables in my dataBase and the second comboBox dispalys the column names from the table the user has selected from the first comboBox?
Thanks
ben
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Have a look at DatabaseMetaData. The method getTables will return the information for your first listbox. The method getColumns will return the information for your second listbox based on the table selected in the first list.
Tom Blough


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Originally posted by Tom Blough:
Have a look at DatabaseMetaData. The method getTables will return the information for your first listbox. The method getColumns will return the information for your second listbox based on the table selected in the first list.
Tom Blough

Hi Tom,
I have been able to get the table names fro the Database with this code

But when I am having trouble to get the Column names from the table the user has selected, could you help me with this part please.
Thanks
ben
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Ben,
See if this helps:

[ March 10, 2004: Message edited by: Tom Blough ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pulling the table names from a Database
 
Similar Threads
why do I get this exception
why is my JTable not showing up?
Jtable cells
Stll having problems
Thowing to many errors