This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC and the fly likes how to retrieve the table list in Access database through JDBC? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to retrieve the table list in Access database through JDBC?" Watch "how to retrieve the table list in Access database through JDBC?" New topic
Author

how to retrieve the table list in Access database through JDBC?

Pier Klein
Greenhorn

Joined: Dec 30, 2003
Posts: 13
It seems I can just retrieve the information from the tables...
Does somebody know how I can get a list of tables in the database?
Thanks!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8705
    
    6

java.sql.DatabaseMetaData


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Pier Klein
Greenhorn

Joined: Dec 30, 2003
Posts: 13
Could you please explain it in details by an example?
Thank you so much!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8705
    
    6

Well, you ask the java.sql.Connection for the database metadata object:

Then you ask the DatabaseMetaData for a list of tables:
Pier Klein
Greenhorn

Joined: Dec 30, 2003
Posts: 13
Thanks,
I got it.
But why I got more than what I want.
In my case,
I have only one table -"Employees" in my Access database,
but the system returns other objects which belong to Access.
Do you have a clue for that?
the output is:
__________________________________
MSysACEs
MSysModules
MSysModules2
MSusObjects
MSysQueries
MSysRelationships
Employees
______________________________________
only "Employees" is what I want.
Thanks!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8705
    
    6

Judging from the names, MSysQueries and MSysRelationships in particular, I'd say they are system tables where Access does it's housekeeping. If you look at the documentation for DatabaseMetaData.getTables() you'll see that the result set it returns had a column called TABLE_TYPE which may help you weed out the unwanted tables.
Pier Klein
Greenhorn

Joined: Dec 30, 2003
Posts: 13
Thanks, Joe Ess!
I think I work it out.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

"Shining Star"
Welcome to Javaranch. We don't have too many rules around these parts, but we do have a Naming Policy. Please adjust your name accordingly. You can change your display name here
Thanks!
[ January 08, 2004: Message edited by: Gregg Bolinger ]

GenRocket - A Test Data Generation Platform
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Future Klein
Thanks for changing you name. However, you are still in violation of the policy. The policy states:
Obviously fictitious names may be locked out.
In order to continue using Javaranch, please adjust your display name appropriately.
Thank You
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to retrieve the table list in Access database through JDBC?
 
Similar Threads
designing a serch engine
JDBC-View
Listing tables in mySQL
inserting image
retrieve data frm database