Java ODBC 和 Microsoft.Jet.OLEDB.4.0
我想使用第三方应用程序提供的连接字符串访问数据库。我有一个示例配置,它具有如下所示的连接字符串:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\to\theDatabase.mdb;Persist Security Info=False
调用时
DriverManager.getConnection("jdbc:odbc:" + connectionString);
出现 SQLException: [Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序
- 第三方应用程序可以毫无问题地访问数据库。
- 操作系统是 Windows XP Service Pack 3 且是最新的。
- system32 文件夹中的 msjet40.dll 版本为 4.0.9511.0(根据 http:// /support.microsoft.com/kb/239114/en-us)
- 该文件存在,我可以使用以下方式访问它
jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};C:\path\to\theDatabase.mdb
我只是不知道我做错了什么。
I want to access a database using a connection string that is given by a third party application. I have one example configuration that has a connection string like the following:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\to\theDatabase.mdb;Persist Security Info=False
Calling
DriverManager.getConnection("jdbc:odbc:" + connectionString);
gives me an SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
- The third party application can access the database without problems.
- The OS is Windows XP Service Pack 3 and up to date.
- The msjet40.dll in system32 folder has version 4.0.9511.0 (up to date according to http://support.microsoft.com/kb/239114/en-us)
- The file exists and I can access it using
jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};C:\path\to\theDatabase.mdb
I just don't know what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题出在您的 odbc 连接上
要连接 Access 数据库,请尝试以下操作:
转到 ControlPanel->AdministrativeTools->DataSource(ODBC)->System DSN->ADD->MicrosoftAccess->MicrosoftAccess。
然后在名称字段中将源名称指定为 connSource。
您必须在 DriverManager.getConnection 方法中使用此名称而不是数据库名称。
因为 getConnectionMethod 采用源名称而不是数据库名称。所以你的代码不起作用。
Problem is in your odbc connection
To connect access database try following
goto ControlPanel->AdministrativeTools->DataSource(ODBC)->System DSN->ADD->MicrosoftAccess->
then in the name field give the Source Name as connSource.
you have to use this name instead of database name in your DriverManager.getConnection method.
Because getConnectionMethod take the source name not the database name. so your code is not working.
这可能是个问题。我不知道有任何用于 OLE DB 数据源的 JDBC 驱动程序。在此,这个问题从三月份开始就没有答案: https://stackoverflow.com/questions/5184046/jdbc-oledb -bin 。
This might be a problem. I don't know of any JDBC drivers for OLE DB data sources. Here on SO this questions sits without answers from March: https://stackoverflow.com/questions/5184046/jdbc-oledb-bin .
请参阅下面的网站,它包含所有数据库的所有变体的连接字符串
http://www.connectionstrings.com/
Refer to the wesite below it contains connection strings of all variants for all the databases
http://www.connectionstrings.com/