The moose likes JDBC and Relational Databases and the fly likes table list 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 "table list" Watch "table list" New topic

table list

shankar vembu
Ranch Hand

Joined: May 10, 2001
Posts: 309
i want to print the list of all tables in a database. i went thru the API DatabaseMetaData.getTables() but am not able to use it bcoz i didnt quite clearly understand the parameters it takes.
could anyone gimme a detailed explanation for this, if possible with an example for a database vendor like sybase,db2 or oracle.
thanx in advance,
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
you were in the right direction. Just check the API for the specific details
public ResultSet getTables(String catalog,
String schemaPattern,
String tableNamePattern,
String[] types)
throws SQLException
Gets a description of tables available in a catalog.
Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
Each table description has the following columns:
TABLE_CAT String => table catalog (may be null)
TABLE_SCHEM String => table schema (may be null)
TABLE_NAME String => table name
REMARKS String => explanatory comment on the table

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
In the getTables method of databaseMetaData interface the four parameter requires an array of table types. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
Anyways you can check the following code.

I agree. Here's the link:
subject: table list
It's not a secret anymore!