java 工作在本地bt无法连接到服务器.显示错误UCAExc:::5.0.1非法字符< :>在索引15:192.168.13.30\C:\Users\Debabrata\Desktop

h9vpoimq  于 2023-03-28  发布在  Java
关注(0)|答案(1)|浏览(95)

我的代码如下。

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
请解决它。

s4n0splo

s4n0splo1#

给定UCanAccess将URI逐字传递给File构造函数,并且java.io.File接受
可选的系统相关前缀字符串,例如磁盘驱动器说明符、UNIX根目录的“/”或Microsoft Windows UNC路径名的“\”,以及(...)
指向一个文件,并考虑到Windows上的UNC指定\\server\c$作为根目录,我会将连接字符串更改为

final String msAccDB= "\\\\192.168.13.30\\C$\\Users\\Debabrata\\Desktop\\somefilename.mdb;memory=false";
final String url = UcanaccessDriver.URL_PREFIX + msAccDB;

额外强调将somefilename.mdb添加到URI。

相关问题