Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retrive Table names in a database

 
Ajit Kanada
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I m trying to retrive the table names in a database.For this i have used resultsetmetadata method getTableName().But to use this i require select query (Select * from tanlename).But i dont know the table name..
Can anyone help me regarding this
i have also tried with DataBaseMetadata methods..they all require table name to supplied as a aargument
Ajit
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is a way that you call with just the Schema, but I don't have my book with me.
if your working with Oracle, you can use all_tables or the user_tables. I believe all databases use a similar scheme where you can access a certain table for this information.
I'll see if I can find the other information for you
Dan
 
Daniel Dunleavy
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to use the java method...
Then there is a DatabaseMetaData getTables where you pass it the catalog name (which I presume if the userid)
HTH
Dan
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As already mentioned, you ned to use the DatabaseMetaData interface. Here is an example. You may want to read the API for more info.

DatabaseMetaData myMT = conn.getMetaData();
String[] myTables = {"TABLE"};
ResultSet tables = myMT.getTables(null,
null, "%", myTables);
String tableName = null;
while (tables.next())
{
System.out.println("In here");
tableName = tables.getString("TABLE_NAME");
System.out.println(tableName);
}
Bosun
 
Ajit Kanada
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thax everyone..
I think my problem is solved now..
Bye
Ajit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic