wood burning stoves 2.0*
The moose likes JDBC and the fly likes get the table names from my database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "get the table names from my database" Watch "get the table names from my database" New topic
Author

get the table names from my database

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Hi
is it possible to know the table names that are
available in my access database
Regards
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
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

Joined: Oct 11, 2000
Posts: 1121

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

Joined: Oct 18, 2004
Posts: 346
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

Joined: Aug 13, 2004
Posts: 177
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

Joined: Oct 11, 2000
Posts: 1121

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get the table names from my database
 
Similar Threads
table selection
Need help in find the text from 1000 Records
Simple hibernate annotation example problem
DB-Metadata
retrieve table name