2

Hi I have the below code to connect to MS Access database on Windows 7 OS. I have changed the Data Source short cut to point to 64bit odbc then 32 bit. But still getting the error as

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at TestDBConnection.main(TestDBConnection.java:21)

And my code is :

import java.sql.Connection;
import java.sql.DriverManager;

public class TestDBConnection {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try
        {
            System.out.println("filename");
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String database = 
                      "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\\Test\\Tests.mdb";
            Connection conn = DriverManager.getConnection(database, "", "");
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }

}

How ever I have SQL Workbench tool through which I can connect to it but not through java code.

Please need help badly as I am struggling with this from past 3 hours searching on Google.

1
  • 2
    You're using the direct path to the .mdb file, not need to create any DSN. Try to add *.accdb also: JDBC:ODBC:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=DBQ=C:\\Test\\Tests.mdb
    – Azad
    Oct 12, 2013 at 13:38

3 Answers 3

8

If your Java app is running in a 64-bit Java Virtual Machine (JVM) then DRIVER={Microsoft Access Driver (*.mdb)} is not going to work because there is no 64-bit version of the Jet database engine. You can...

  • Download and install the 64-bit version of the Microsoft Access Database Engine from here, and then use DRIVER={Microsoft Access Driver (*.mdb, *.accdb)} in your code.

... or ...

  • Run your Java app in a 32-bit JVM and continue to use the existing DRIVER= string. The related answer here might prove helpful if you choose this option.

... or ...

  • Use the UCanAccess JDBC driver for Access databases. It is a free, open-source, pure Java implementation so it works on both 32-bit and 64-bit systems, both Windows and non-Windows. It also works with Java 8 (which has dropped the JDBC-ODBC Bridge). For more details, see:

        Manipulating an Access database from Java without ODBC

2
  • If anyone is having this error using 64 bit JVM try adding "*.accdb" to your "DRIVER=..." string. Worked for me.
    – andymal
    Apr 29, 2014 at 15:25
  • Reverting to 32-bit saddened me, but having my script exporting correctly made me happy again. (I live a simple life)
    – sMaN
    Oct 23, 2014 at 2:36
1

You can install the 64 ODBC drivers for Access available from Microsoft

http://www.microsoft.com/en-us/download/details.aspx?id=13255

3
  • I was restricted from this route due to 32-bit office programs being installed.
    – sMaN
    Oct 23, 2014 at 2:38
  • Do you mean, when office 32bit is installed, you can't also install the 64bit odbc drivers on the same system? Oct 23, 2014 at 7:06
  • I think so as per the error message I received. Windows recommended I uninstall my 32-bit programs.
    – sMaN
    Oct 23, 2014 at 23:32
0

1) you will have to configure System dsn (Driver Microsoft Access Driver(.mdb,.accdb)) 2) link .mdb database in above configuration and write below code.

 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 String database = "jdbc:odbc:systemdsnname";
 Connection conn = DriverManager.getConnection(database, "", "");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.