Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get the table names from my database

 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
is it possible to know the table names that are
available in my access database
Regards
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use getMetaData() of ResultSet which return ResultSetMetaData object. This can be used to find info about table,columns name,type in ResultSet.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Domanjit,
I believe you mean the "getMetaData()" method in the Connection interface -- which returns a DatabaseMetaData object. Then you can use the "getTables()" method.

Good Luck,
Avi.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No,

I meant the ResultSetMetaData whose method getTableName(int column) can be used. With DatabaseMetaData-getTables() method, one needs to have prior information about its various parameters.
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys and thanks for your time
you have been very helpful
my application is working now
the code:

<b>

Vector tables = new Vector();
DatabaseMetaData dbmt = cn.getMetaData();
ResultSet myRs = dbmt.getTables("","","",null);
while(myRs.next())
tables.addElement(myRs.getString("TABLE_NAME")) ;

</b>

the Vector tables contains the names of the tables
in my DB, this example worked on mysql on access an
exception was thrown.
againg thanks for the Help
Best Regards, Omar
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damanjit,
The "getTable()" method is not supported by some JDBC drivers -- since it is not always easy to figure out what table a column in a "ResultSet" belongs to. However, "DatabaseMetaData" works with the data-dictionary, and nearly all databases have a data-dictionary. So "DatabaseMetaData" is nearly always guaranteed to provide a list of database tables.

I believe Omar said that he required a list of all the database tables. In order to get a "ResultSetMetaData" object, you first require a "ResultSet" object. And in order to get a "ResultSet", you need to perform a query. Please tell me what query needs to be performed, in order to obtain the list of all database tables -- using "ResultSetMetaData"? (Or am I missing something?)

Good Luck,
Avi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic