This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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