1

I was trying this method : How can I get table names from an MS Access Database? and others, but it does nothing. Also, an error occurred said that I have no permission to read MSYSOBJECTS.

By using Java, how to get list of table names from Ms. Access 2.0 ?

I need this because I'm not permitted by them to change the database format nor the version itself.

Community
  • 1
  • 1
poring91
  • 393
  • 7
  • 22
  • 1
    Every database is a little different, but take a look at [this example](http://stackoverflow.com/questions/2780284/how-to-get-all-table-names-from-a-database) and possibly [this example](http://stackoverflow.com/questions/9288966/delete-table-if-exists-in-microsoft-access/9289395#9289395) as well... – MadProgrammer Sep 28 '13 at 00:50
  • 2
    Please copy and paste your working code to create an answer to this question. (On Stack Overflow it is quite acceptable for a user to answer his/her own question.) – Gord Thompson Sep 28 '13 at 13:04
  • Ok, I've fixed it. There was a fault in placing Class.forName and DriverManager. It should be caught in try-catch – poring91 Sep 29 '13 at 08:16

1 Answers1

2

From MadProgrammer's info in his comment (Thank you so much), finally I found the solution. So I use this slice of code

Connection conn;
String fileName = "C:/folder/AccessDB.mdb";
String dbString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+fileName+";";

try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection(dbString, "", "");
    DatabaseMetaData md = conn.getMetaData();
    ResultSet rs = md.getTables(null, null, "%", null);
    String temp;
    while (rs.next()) {
        temp = rs.getString(3);
        if(!temp.contains("MSys")) {
            System.out.println(temp);
        }
    }
}
catch(ClassNotFoundException|SQLException e) {
    e.printStackTrace();
}
poring91
  • 393
  • 7
  • 22