| 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
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
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
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
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
|
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
|
 |
 |
|
|
subject: Database Metadata
|
|
|