2

I am trying to input some data into a microsoft access database, but I always get the same error. Here is my code:

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

public class testDDB {

public static void main(String[] args) {
    try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
       String filename = "C:\\test\\Database1.mdb";
       String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=";
       database+= filename.trim() + ";}"; // add on to the end 
       Connection con = DriverManager.getConnection( database ,"",""); 
    }catch(Exception e){
        e.printStackTrace();
    }

}

I get the following errors:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)

I have looked in previous posts, I found similar issues but I still do not find the solution. My computer is running on 64bit, and when I go to C:\Windows\SysWOW64\obdcad32.exe, I find enter image description here

So it seems that I have a 64bit version of ODBC...

Mistalis
  • 17,793
  • 13
  • 73
  • 97
Nefarious62
  • 161
  • 1
  • 5
  • 15
  • 1
    Possible duplicate of [JDBC driver MS Access connection](http://stackoverflow.com/questions/16626301/jdbc-driver-ms-access-connection) – DimaSan Jan 05 '17 at 15:21
  • Have you set up your access database as an ODBC data source? – BretC Jan 05 '17 at 15:21
  • This could help you [JDBC ODBC Driver](http://stackoverflow.com/questions/17115632/microsoftodbc-driver-manager-data-source-name-not-found-and-no-default-drive) – Kedar1442 Jan 05 '17 at 15:23
  • Hi BretC, I am not sure to understand your question. Should I link the ODBC user data source to this file in particular? – Nefarious62 Jan 05 '17 at 15:29
  • It's been ages since I used Access because I always found it somewhat lacking and would never dream of using it in the real world... There's loads of companies out there with rubbish, creaking access databases hindering their businesses!! Basically, open Control Panel, search for "ODBC" then set up an ODBC source for your access database (Google is your friend). I seem to rememeber that if I set up one called "myDB" I could connect to it using the DB "url: jdbc:odbc:myDB". Better yet, use a DBMS that is more suited to the real world!! – BretC Jan 05 '17 at 15:37

1 Answers1

1

when I go to C:\Windows\SysWOW64\obdcad32.exe, I find

| MS Access Database ... Microsoft Access Driver (*.mdb, *.accdb)

So it seems that I have a 64bit version of ODBC

The folder name "SysWOW64" can be a bit misleading. It contains the components for the 32-bit "WOW" subsystem (i.e., "[32-bit]Windows On Windows[64]").

So, "SysWOW64\obdcad32.exe" is actually the 32-bit ODBC administrator and you in fact have the 32-bit version of the Access "ACE" ODBC driver installed. Therefore you need to run your application under a 32-bit version of the JRE (Java Runtime Environment) in order to use that ODBC driver.

Also, bear in mind that the JDBC-ODBC Bridge was removed from Java 8, so your JRE must be for Java 7 or earlier. (For Java 8 and later, consider using the UCanAccess JDBC driver. Details here.)

Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418