• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

get the table names from my database  RSS feed

 
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
 
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.
 
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.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!