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

末鹿安然 提交于 2019-12-04 04:24:27

问题


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


回答1:


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";



回答2:


The database driver can only handle his specified protocolls. Most of jdbc drivers can only handle the network protocol for his specific database server.

You are using the access jdbc driver which can only handle file access to a given accdb file.

When you try an url like:

jdbc:ucanaccess://servername/etc/MyDB.accdb

The driver makes a local file access to this path which does not exist localy. What you expect is, that the driver would make up a SMB/CIFS connection to your server, which he can't!

You have to map the SMB/CIFS share over your OS on to a local drive letter. Because then the OS is handling the network SMB/CIFS stuff for you. And the JDBC driver can access the file as it would access a local file.



来源:https://stackoverflow.com/questions/31814796/unable-to-connect-to-a-database-on-a-shared-drive-ucanaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!