UCanAccess "User lacks privilege or object not found" error on opening database

user3656992 picture user3656992 · Dec 29, 2014 · Viewed 7k times · Source

I have a Java program that needs to pull from a Microsoft Access database. I recently had to change the code to use UCanAccess instead of ODBC as the JDBC-ODBC Bridge is not supported in Java SE 8 (Manipulating an Access database from Java without ODBC)

When I run the code shown below (just the sample code given on the UCanAccess website), I get an error -

ERROR: net.ucanaccess.jdbc.UcanaccessSQLException: user lacks privilege or object not found: NULL

The code is as follows

Connection conn=DriverManager.getConnection("jdbc:ucanaccess://Z:\\Assignment.accdb");
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM tbl2014janjun"); //tbl2014janjun ORDER BY ID
while (rs.next()) {
    System.out.println(rs.getString(1));
}

While testing, I noticed that a separate database, Work Order, is able to be accessed by this code and the output is as expected. In addition, whenever this code tries to run, it produces the locking laccdb file in the server directory. Because of this, I believe the issue lies with user privileges. While searching this site for possible answers, most of them related to the second half of the error message - the table was misspelled, etc. I have made sure that the spelling/location/file structure is correct.

Thank you for any help you can provide.

Answer

mljm picture mljm · Aug 3, 2015

I had exactly the same issue after moving from Tomcat 6 to 7. Two databases in the same place with the same tables and columns, just the data is different (different projects). One worked fine, the other one gave the above-mentioned error.

Fixed it by doing a "Compact and Repair Database" operation from within the Access windows app. (In Access 2007 it's Manage > Repair from the main toolbar dropdown.)