且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java无法使用Eclipse连接到MS Access数据库

更新时间:2022-11-30 07:45:05

getConnection()

1) getConnection( String url, Properties info )

1) getConnection( String url, Properties info )

url- 格式为jdbc:subprotocol:subname

url - a database url of the form jdbc:subprotocol:subname

信息- 任意字符串标记/值对作为连接参数的列表; 通常至少应包括用户"和密码"属性

info - a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included

2) getConnection( String url, String user, String password )

2) getConnection( String url, String user, String password )

url-格式为jdbc:subprotocol:subname

url - a database url of the form jdbc:subprotocol:subname

用户- 代表建立连接的数据库用户

user - the database user on whose behalf the Connection is being made

密码- 用户的密码

password - the user's password

3) getConnection( String url )

url- 格式为jdbc:subprotocol:subname

url - a database url of the form jdbc:subprotocol:subname

考虑到您使用的是最后一个构造函数,看来您的url语法不正确.我不熟悉MS Access,但会提供我在另一个答案中发现的建议.

Considering you're using the last constructor, it seems your url syntax in incorrect. I'm not familiar with MS Access, but I'll offer a suggestion I found on another answer.

这是你的语法

"jdbc:odbc:; DRIVER = Microsoft Access Driver (*.mdb, *.accdb); DBQ = DB.accdb"

我发现了正确的语法

File f = new File("\\\\***\\***\\****\\***.accdb");

"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + f.getAbsolutePath();

好像您在odbc之后有多余的分号和多余的空格.也许您想尝试上面的语法,看看会发生什么.我不确定文件部分,但是如果在进行分号/空格修复后您的URL仍然失败,您可能需要调查一下.

Looks like you have an unnecessary semicolon after odbc and an extra space. Maybe you want to try the above syntax and see what happens. I'm not sure about the file part, but you may want to look into it if your url still fails after making the semicolon/space fix.

还请查看此问题,以获取有关另一个选项的更多信息与用户名和密码

Check out this question also for more info on another option Connection with username and password