This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Listing out tables in a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Listing out tables in a database" Watch "Listing out tables in a database" New topic
Author

Listing out tables in a database

Suma K Gowda
Greenhorn

Joined: Feb 03, 2004
Posts: 12
Hi

I'm connecting to a database and want to display all the available tables under that database. How can I do it?

I checked the whole java.sql api..but didn't find anything which actually displays the tables under a database..

Plz help
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

All the metadata functionality of JDBC is supplied by jav.sql.DatabaseMetaData. If there's nothing in there to do what you want, you'll have to resort to the verdor-specific queries for doing this ("show tables" in mysql, "select * from user_tables" in Oracle, "select * from sysobjects where xtype ='U'" in MSSQL etc.)

[ June 11, 2004: Message edited by: Paul Sturrock ]
[ June 11, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Exactly.Will give you all tables and views in a given schema. See the javadoc for further information on the metadata API. For a detailed discussion, the standard recommendation is the excellent The JDBC API Tutorial and Reference (reviewed in the Bunkhouse; I should add that as one of the tech reviewers on this book I'm not unprejudiced).

- Peter
[ June 11, 2004: Message edited by: Peter den Haan ]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Listing out tables in a database
 
It's not a secret anymore!