File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Database Metadata Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database Metadata" Watch "Database Metadata" New topic
Author

Database Metadata

Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
My question is, is it possible to look at the structure of a database... for example table names, the columns in each table and each columns type?
It would seem that MetaData (data about the data)would do that. However I have played with it for a few minutes and it seems that is not the case
Thanks,
Bill
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Well, don't know if you are using the correct Interfaces.
ResultSetMetaData can determine column titles and column types to name a couple, but the 2 you had asked about.
DatabaseMetaData will allow you to discover Table Names, Priviliges, Stored Procedures, etc.


GenRocket - Experts at Building Test Data
Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
Yep, those were the 2 that I was using. Then I was attempting to iterate through the ResultSet of each of those types.
Unfortunately, Only one table was returned.
Obviously, there are more.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Can we see some code?
Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
DatabaseMetaData dbMetaData =
getConnection().getMetaData();
//ResultSet schemas = dbMetaData.getSchemas();
ResultSet tables =
dbMetaData.getTables(null, null, null, null);


while(tables.next())
{
ResultSetMetaData rsMetaData = tables.getMetaData();
System.out.println(rsMetaData.getColumnCount());
int iterator = rsMetaData.getColumnCount();
for(int count = 1; count < iterator; count++)
{
System.out.println(
rsMetaData.getColumnName(count));
}

}
Here is the output:
TABLE_SCHEM
TABLE_NAME
TABLE_TYPE
5
TABLE_CAT
TABLE_SCHEM
TABLE_NAME
TABLE_TYPE
Yes, I have played with it somemore
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database Metadata