Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want connect my MS access file with Java GUI program,but I have problem with connection....

I have Windows 7 64b, and ms office 2007. When I opened the ODBC driver manager in the control panel I havent found any driver for Microsoft Access (maybe when I started the ODBC is started running the 64bit ODBC, now I think is running the 32bit ODBC. I read this and I make it : "jdbc-odbc connection for window 7 64 bit machine.. 1 . Right click Data source (ODBC)..go to properties change the folloing thing

target [ %SystemRoot%SysWOW64odbcad32.exe ] start in : [ %SystemRoot%System32 ]

press enter and continue as admin source: source link " ) Now when I start in conctrol pannel the ODBC I can see the driver screenshoot

My program code(I tried two ways but I have same error):

        public void Connect() {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

 //    String DatabaseFile = "D:java/Invertory.mdb";       
//            String DATABASE =
//                    "jdbc:odbc:Driver="
//                    + "{Microsoft Access Driver (*.mdb, *.accdb)};"
//                    + "DBQ=" + DatabaseFile;`enter code here`
 String DATABASE ="jdbc:odbc:Driver= Microsoft Access Driver (*.mdb, *.accdb);DBQ=Invertory.mdb";
           CONEX = DriverManager.getConnection(DATABASE);

        } catch (Exception X) {
          X.printStackTrace();
            //JOptionPane.showMessageDialog(null,e);
        }
    }

error

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use UCanAccess JDBC Driver :

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://<mdb or accdb file path>",user, password); 
for example: 
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://c:/pippo.mdb");

So for your example it will be Connection conn=DriverManager.getConnection("jdbc:ucanaccess://"+path)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...