3

Is there any way to list the names of all of the tables in an MDB file? I am attempting to create a program that tests the user on Quizbowl questions. I would like to organize the questions and answers so that each question set is located within its own table. Simply put, I am unfamiliar with the API for Jackcess - I have tried searching to see if there is a method that would do this, but have failed.

Thank you.

1 Answers1

8

Simply use the .getTableNames() method of the Database object, like this:

import java.io.File;
import com.healthmarketscience.jackcess.Database;

// ...

String dbFileSpec = "C:/Users/Public/mdbTest.mdb";
try (Database db = DatabaseBuilder.open(new File(dbFileSpec))) {
    for (String tableName : db.getTableNames()) {
        System.out.println(tableName);
    }
} catch (Exception e) {
    e.printStackTrace(System.err);
}
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • **Which one should I import? for `Database`:** *`com.healthmarketscience.jackcess.Database`*, *`org.hibernate.boot.model.relational.Database`*, *`org.hibernate.dialect.Database`*, *`org.hsqldb.Database`*, *`org.springframework.orm.jpa.vendor.Database`* **and for `File`** *`con.sun.java.util.jar.pack.Package.File`*, *`java.io.File`*, *`org.apache.tomcat.jni.File`* – Partho63 Oct 21 '19 at 11:53