2

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.

Community
  • 1
  • 1
user3656992
  • 143
  • 1
  • 8
  • I've never used UCan.. but I think your first clue is at the end of message where it says 'Null' - like it is missing something. Then if you look at the path to your database, are you sure it is resolving "//Z:\\Assignment.accdb" correctly? Is that the correct path? As a test, why not fully qualify the path (assuming your '\\' is intentional). Since you are getting the LDB file your permissions *may* be ok. – Wayne G. Dunn Dec 30 '14 at 00:41
  • I am sure that the path is resolving correctly. To clarify, the accessible database is located in the same directory, and I receive the correct output. However, simply changing the file name to Assignment creates the above problem. As far as I can tell, the are no notable differences between the two databases. – user3656992 Dec 30 '14 at 14:12
  • Can you post the same code for the db that is working? If you can get to another db in same folder, then I would compare all the permissions between the two db's (should be no need to check folder permissions). – Wayne G. Dunn Dec 30 '14 at 15:13
  • Issue might happen at the connection time so your report might be incomplete. Please append along the exception stacktrace. – jamadei Dec 30 '14 at 18:50
  • Sorry, my workplace's internet went down yesterday. I believe the problem lies in the database permissions, as I can access other databases in the same directory. I'll try to fix the problem using this information, and might ask a new more focused question if I still can't find an answer. Thanks for your help. – user3656992 Dec 31 '14 at 14:14
  • The UCanAccess distribution contains the utilities `console.bat` for Windows and `console.sh` for Linux (*et. al.*). They will prompt you for the location of the database file and then scan it, opening each table/query and reporting any errors it encounters. Try that and see if it gives you any additional clues as to the cause of your difficulty. – Gord Thompson Jan 06 '15 at 21:50
  • Thank you for making me aware of the `console.bat` utility. After reviewing the error, it seems that the connection does not load the tables, but somehow loads the relevant indexes. I am unsure why this could be the case. I can post the results, but they do not tell me much more than that. – user3656992 Jan 07 '15 at 14:48
  • Just as a sort of final update, I eventually just had to roll back to Java 7 and re-use the old code. For whatever reason, it can access Assignment.accdb just fine. – user3656992 Jan 09 '15 at 19:40

1 Answers1

2

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.)

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
mljm
  • 317
  • 2
  • 11