0

When trying to connect to an MS Access database using ucanaccess I keep getting the "No suitable driver found" error when using the relative path to my database:

SEVERE: null
java.sql.SQLException: No suitable driver found for jdbc:ucanaccess:PatientLog.accdb
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at connectiontester.OpenDB.openConnection(OpenDB.java:33)
    at connectiontester.ConnectionTester$1.handle(ConnectionTester.java:41)
    at connectiontester.ConnectionTester$1.handle(ConnectionTester.java:37)

To make sure my relative path was correct, I used DirectoryStream to get a directory list, and my database (PatientLog.accdb) does show up in the list. Curiously, when I use the full path the error disappears.

Anyone know why? Anyone have a solution so I can use the relative path?

Using Java 1.8 update 45

Netbeans 8.0.2

Windows 8

Ucanaccess 2.0.9.5 (and dependencies)

James_D
  • 201,275
  • 16
  • 291
  • 322
John
  • 165
  • 2
  • 3
  • 15

1 Answers1

1

The error message shows that you are missing the two slashes immediately before the file name. When specifying a relative path your connection URL should look something like this:

jdbc:ucanaccess://PatientLog.accdb

When specifying a full path you should use something like this:

jdbc:ucanaccess://C:/Users/Gord/Desktop/PatientLog.accdb
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Actually I've tried both ways and get the same error. – John Jul 13 '15 at 19:51
  • But the exception isn't ambiguos, if ucanaccess can't find the file a UCanAccessException with a wrapped FileNotFoundException is thrown(and the message given file doesn't exist). You simply lost the // after jdbc:ucanaccess: so a "No suitable driver found" is thrown by the DriverManager(it means that ucanaccess didn't accept the jdbc url) . – jamadei Jul 13 '15 at 20:36