1

I am trying to connect to a MS Access database using hsqldb in java. I added all the libraries I needed, but in the end I still get an exception: Exception in thread "main" java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: MESSAGES Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: MESSAGES

Code below:

    Connection conn = null;
try {
    Class.forName("org.hsqldb.jdbcDriver");
    conn = DriverManager.getConnection("jdbc:hsqldb:D:/sms4.accdb", "sa", "");
} catch (SQLException e) {
    e.printStackTrace();
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select * from Messages"); //here is where I get the error
mamba
  • 61
  • 2
  • 10

1 Answers1

1

HSQLDB cannot (as far as I know) open an Access database directly. You will need to use the UCanAccess JDBC driver. (It uses HSQLDB in the background, but your Java application never manipulates the HSQLDB "backing database" directly.)

For more information, see

Manipulating an Access database from Java without ODBC

Community
  • 1
  • 1
Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
  • 1
    Yup, thank you for the info! I removed Class.forName and modified the next line into: DriverManager.getConnection("jdbc:ucanaccess://D:/sms4.accdb") and now everything is ok. – mamba Mar 10 '15 at 13:19