Can't connect to MS Access DB with Windows-64bit [duplicate]

强颜欢笑 提交于 2019-12-24 07:31:11

问题


Possible Duplicate:
Microsoft Access and Java JDBC-ODBC Error

I had issues with creating my DB to begin with. I have a 64bit version of Windows 7 and found out the error was with Microsoft Office being 32bit. I was able to create my Access database by using the odbcad32.exe found in c:\Windows\sysWOW64\odbcad32.exe

Now in my Java code I am simply trying to get connected but am running into issues again that seem to be related, and make me feel like at the most I just didn't set up the database correctly. JavaDB is the name of my data source I created in the ODBC:DSA as you can see here: http://i.imgur.com/9n19x.png

I've been searching all over the internet but can't really find a solid definite answer. Could really use the help, thanks in advanced!

EDIT: I cleaned up my code and now my error is different. I have my physical database file in my project folder at C:\Eclipse\project1\src - I have set it up as well like I said in the ODBC to be the same.

EDIT EDIT: Well, after hours and hours of research I ended up just figuring it out finally. The issues wasn't as much my code, as it was compatibility issues with Windows x64BIT and 32 bit drivers in Office. This article helped me fix it, and now it works! http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/

import java.sql.*;

public class DBTester {

public static void main(String[] args) throws SQLException, ClassNotFoundException {

try 
{

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


    String fileName = "C:/Eclipse/school/bin/RegistrationDB.mdb";


    String dB = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+fileName;
    Connection connection = DriverManager.getConnection(dB,"","");

    System.out.println("connected");

    Statement s = connection.createStatement();
    s.close();
    connection.close();

} catch(Exception ex)
{

    ex.printStackTrace();

}


} // end main

} // end class

回答1:


After much research and seeing tons of unanswered questions related to mine here and other places I stumbled upon an article with a simple fix that made my want to hit my head into my desk.

http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/

If you have a 64bit Windows 7 machine and a 32Bit version of Access - you are going to have issues. From this guys article, I was able to uninstall my current MS Access - and -reinstall a 64 bit version. Re-added my DB sources and everything worked.



来源:https://stackoverflow.com/questions/13782957/cant-connect-to-ms-access-db-with-windows-64bit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!