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 DatabaseMetaData API 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 "DatabaseMetaData API" Watch "DatabaseMetaData API" New topic

DatabaseMetaData API

VenuGopal Reddy

Joined: Mar 06, 2007
Posts: 2
I want to display all the meta data information like,

1.List Of Tables
2.List Of Columns for in a table
3.Constraints on columns and tables
4.Primary Keys
5.foreign Keys...

i tried in the followimg way....

DatabaseMetaData metadata=con.getMetaData();
ResultSet rs=metadata.getTables(null,"Schema","*",null);

from this point i could not proceed further...

Please let me know code examples for this meta data or let me know how to proceed further...

suggesting any specific books with code examples related to meta data wud be helpful for me..

Thanks In Advance..
Eric Gero
Ranch Hand

Joined: Jul 20, 2005
Posts: 73
You can get the table names as follows:

DatabaseMetaData dbmd = dbConn.getMetaData();
ResultSet rsTables = dbmd.getTables(server.getInitialCatalog(), null, null, null);
String tableType = null;

while ( {
tableType = rsTables.getString("TABLE_TYPE");
if (tableType.equals("TABLE")) {
tableListModel.add(tableCount, rsTables.getString("TABLE_NAME"));

This link has a pretty good explanation of it.

VenuGopal Reddy

Joined: Mar 06, 2007
Posts: 2
Thanks Very Much Eric...Will go thru the link you have suggested...
I agree. Here's the link:
subject: DatabaseMetaData API