Java – The specified DSN contains an architecture mismatch between the Driver and Application. JAVA

javaodbc

I'm trying to connect to a database made by MS Access using Java, but I cannot seem to manage. I am using ODBC and I'm getting this exception:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

My Java:

package javaapplication2;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 *
 * @author Owner
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     * 
     */


    public static void main(String[] args) {
        // TODO code application logic here
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String sourceURL = new String("jdbc:odbc:myDatabase");
            System.out.println(sourceURL);
            Connection dbConnection = DriverManager.getConnection(sourceURL,"admin","");

            Statement myStmt  = dbConnection.createStatement();

            String query = "INSERT INTO People(ID, Name, Surname, Age, Contact, Location, Course) VALUES"
                    + " (1007, 'Elroy', 'Smith', '33', 21366688, 'Somewhere', 'somecourse')";

            myStmt.executeUpdate(query);

            ResultSet results = myStmt.executeQuery("SELECT * FROM People");

            while(results.next())
            {
                System.out.print(results.getString(1));
                System.out.print(results.getString(2));
                System.out.print(results.getString(3));
                System.out.println(results.getString(4));

            }

            results.close();

        }
        catch(ClassNotFoundException cnfe)
        {
            System.out.println(cnfe);
        }
        catch(SQLException sqle)
        {
            System.out.println(sqle);
        }
    }
}

Best Answer

None of these did it for me. I did find the answer on MSDN. There were hints to it though. The architecture in the error is referring to 32 vs 64 bits. My solution was to find out which my app is running under (Access) which 2010 is 32b. I found this by looking in the Process tab of Task Manager where all 32b processes have * 32 the end of their names. As was said, the control panel will launch the 64 bit version of ODBC from here

c:\windows\system32\odbcad32.exe

and the 32 bit version is here:

c:\windows\sysWOW64\odbcad32.exe (easiest to copy and paste into run dialog)

So I set up DSNs with names ending in 32 and 64 in each of the corresponding ODBC control panels (AKA Administrator) that pointed to the same thing. Then, I picked/pick the correct one based on whether the app using it is 32b or 64b.