File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes get the table name dynamically 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 "get the table name dynamically" Watch "get the table name dynamically" New topic

get the table name dynamically

joseph prabhu
Ranch Hand

Joined: Feb 26, 2008
Posts: 162
hi joe here

is there any method to get the names of the tables present in a database

Thanks in advance
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Have a look at the methods available to you via java.sql.DatabaseMetaData.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

Retrieve meta-data from the database through the established connection like this.

and use methods of this Object to get Database MetaData.

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

The JDBC Meta data answer is the best since its database independent, but you should also be aware many DBMS's keep meta data tables available. For example, in MYSQL there's often an information_schema database schema which contains tables that can be used to read schema/table/column information, as you would normal SQL queries.
[ June 02, 2008: Message edited by: Scott Selikoff ]

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: get the table name dynamically
It's not a secret anymore!