Wizard Wizard - 8 months ago 79
Java Question

Unable to connect to a database on a shared drive - UCanAccess

I've setup my application to connect to a Access database through UCanAccess however I'm unable to connect to a database that is located on the shared drive. See below for examples.

String databasePath = "jdbc:ucanaccess://C:/Desktop/MyDB.accdb" \\\\ this works
String databasePath = "jdbc:ucanaccess://servername/etc/MyDB.accdb" \\\\ does not work and throws no suitable driver found exception

Interesting enough when I map my folder on the shared drive to some letter e.g. P: - it successfully connects.

String databasePath = "jdbc:ucanaccess://P:/servername/etc/MyDB.accdb" \\\\ this works

Is it possible to go around this? My users have r/w permissions to the folder but I don't want to map drives on each machine.

Answer Source

You simply don't have enough forward slashes in your connection URL to represent a UNC path. As you have noted, for a local connection to C:\Desktop\MyDB.accdb you can use

String databasePath = "jdbc:ucanaccess://C:/Desktop/MyDB.accdb";

Similarly, for a UNC connection to \\servername\etc\MyDB.accdb you can use

String databasePath = "jdbc:ucanaccess:////servername/etc/MyDB.accdb";