Java MSAccess DSN Less

发布于 2024-11-14 08:22:50 字数 869 浏览 10 评论 0原文

所以问题是我想连接到每次打开时都有密码的 msaccess 数据库

  • 如果我直接打开访问文件,密码就有效。
  • 如果删除密码,我可以建立连接,这意味着如果没有涉及密码,我的代码就可以工作
  • 密码是使用数据库工具 MS Access 2007 中的“设置数据库密码”设置的
  • (但我使用了 .mdb)

代码

String dbFile = "db.mdb";
String connectionString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
String driverID = ";DriverID=22;READONLY=true;pwd=qwer}";
if (CONNECTION == null || CONNECTION.isClosed()) {
   dbURL = connectionString + dbFile.trim() + driverID;
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   CONNECTION = DriverManager.getConnection(dbURL);
}

----------------------------------------------
Error Code : java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid password.
----------------------------------------------

这是我已经的 尝试向获取连接添加参数,但没有成功。 请帮忙:)

So the problem is that I want to make a connection to a msaccess database that has password every time you open it.

  • The password works if I directly open the access file.
  • I can make the connection if I remove the password, which means my code works if there is no password involve
  • The password was set using Set database Password in the database tools
  • MS Access 2007(but i used the .mdb)

Here's the code

String dbFile = "db.mdb";
String connectionString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
String driverID = ";DriverID=22;READONLY=true;pwd=qwer}";
if (CONNECTION == null || CONNECTION.isClosed()) {
   dbURL = connectionString + dbFile.trim() + driverID;
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   CONNECTION = DriverManager.getConnection(dbURL);
}

----------------------------------------------
Error Code : java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid password.
----------------------------------------------

I already tried adding parameters to the get connection but it did not work.
Please Help :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静谧 2024-11-21 08:22:50

MS Access 数据库文件有 2 种类型的密码:

  1. 用户密码
  2. 数据库密码

使用用户密码时,您可以在连接字符串中提供用户名和密码。

;User Id=admin;Password=;

对于数据库密码,您需要在连接字符串中使用不同的标识符来区分该密码是数据库密码而不是用户密码。

;Database Password=MyDbPassword;

我个人不使用数据库密码。该功能并没有提供太多的安全性,因此看起来麻烦大于其价值。

编辑:我不知道是否可以通过 ODBC 连接提供数据库密码。我发现的所有连接示例在包含数据库密码时都使用了 OLE DB。

Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\somepath\\mydb.mdb;" & _
                 "Jet OLEDB:Database Password=MyDbPassword;", "admin", ""

也许可以从当前的 Access ODBC 驱动程序切换到 Microsoft OLE DB Provider for ODBC。或者也许使用当前的 ODBC 驱动程序(如果您切换

Database Password=MyDbPassword;

Jet OLEDB:Database Password=MyDbPassword;

我不知道)。但在我看来,数据库密码只是妨碍你。您已经知道如果从数据库中删除密码就可以连接。

There are 2 types of passwords for MS Access database files:

  1. user passwords
  2. database password

With a user password, you supply the user name and password in the connection string.

;User Id=admin;Password=;

For a database password, you need a different identifier in the connection string to distinguish the password as a database password rather than a user password.

;Database Password=MyDbPassword;

Personally I don't use a database password. That feature doesn't offer much in the way of security, so it seems like it's more trouble than it's worth.

Edit: I don't know if it's possible to supply a database password with an ODBC connection. All the connection examples I found used OLE DB when including a database password.

Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\somepath\\mydb.mdb;" & _
                 "Jet OLEDB:Database Password=MyDbPassword;", "admin", ""

Perhaps it could work to switch from the current Access ODBC driver to the Microsoft OLE DB Provider for ODBC. Or maybe with the current ODBC driver if you switch

Database Password=MyDbPassword;

to

Jet OLEDB:Database Password=MyDbPassword;

I don't know. But seems to me the database password is just getting in your way here. You already know you can connect if you remove the password from the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文