我的代码如下。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
public static void main(String[] args) {
String msAccDB= "192.168.13.30/C:/Users/Debabrata/Desktop;memory=false";
String url = "jdbc:ucanaccess://"
+msAccDB;
Connection conn = null;
String user ="";
String password="";
try {
// register UCanAccess driver
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
// establish JDBC connection
conn = DriverManager.getConnection(url,user,password);
// use the connection to query the database
// ...
System.out.println("Connection established successfully.");
} catch (ClassNotFoundException e) {
System.out.println("UCanAccess driver not found: " + e.getMessage());
} catch (SQLException e) {
System.out.println("Connection failed: " + e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error closing connection: " + e.getMessage());
}
}
}
}
这段代码在本地访问mdb文件时工作正常,但在尝试连接服务器时遇到错误
连接失败:UCAExc:::5.0.1非法字符索引15<:>:192.168.13.30\C:\Users\Debabrata\Desktop
请解决它。
1条答案
按热度按时间s4n0splo1#
给定UCanAccess将URI逐字传递给
File
构造函数,并且java.io.File
接受可选的系统相关前缀字符串,例如磁盘驱动器说明符、UNIX根目录的“/”或Microsoft Windows UNC路径名的“\”,以及(...)
指向一个文件,并考虑到Windows上的UNC指定
\\server\c$
作为根目录,我会将连接字符串更改为额外强调将
somefilename.mdb
添加到URI。