• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database Metadata

 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we see some code?
 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic