• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Database Metadata

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we see some code?
 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic