Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

get the table names from my database

 
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: 1143
1
Eclipse IDE Oracle Java
  • 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: 1143
1
Eclipse IDE Oracle Java
  • 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.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic