The specified DSN contains an architecture mismatch between the Driver and Application. JAVA
Asked Answered
W

18

93

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);
        }
    }
}
Wilt answered 17/1, 2012 at 13:56 Comment(3)
Are you using a 64-bit jvm? If so, you need a 64-bit odbc driver.Angularity
Yes, I think I am. I found the 64bit version of the odbc in C:\Windows\SysWOW64 but it's not the same one that the control panel turns on.Wilt
Can't install 64bit driver cause my other office products are 32bit :/Hanzelin
Z
140

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.

Zootoxin answered 21/9, 2012 at 19:59 Comment(9)
i had tried 64 bit version and run it as administrator, but it also does not work!!Nimiety
There must be bit-harmony. If the app is 32, there must be a 32 bit config for it. If the app is 64, you have to have one that's 64. I did not try creating configs with the same name because I did not want them to get out of sync (forget to change both at the same time). You did not give me enough info to try to offer suggestions. I hope you figured it out. (Why can't they do the so very simple thing and create one 64 bit app that configures both 64 and 32 bit environments???)Zootoxin
And as was stated below yet not obvious, the drivers involved also have to match (probably best to install both 32 and 64) though I don't think you can pick the driver if it wasn't the proper architecture.Zootoxin
This also helped me decipher why my 32bit Excel could not connect to our Hadoop Hive Server using the 64bit Cloudea Hive ODBC Driver. Once I switch to the 32bit connector it worked great!Persian
@PecosBill i had done this changes and created ODBC Data Source but still getting this error. [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application.Michaels
Thank you! It's crazy that there's a 32 bit ODBC link in the control panel (in Win2008 e.g.), but it takes to to the 64 bit dialogue! Furthermore the 64 bit ODBC dialogue shares the User DSNs with 32 bit, but not the System DSNs... This has confused me for years, but your specific link to the exe has totally clarified it.Shirleneshirley
Bipin, all of the bits must line up. If you have a 32 bit application, you have to have 32b drivers, 32b config, and 32b Java. In most/all cases, you can have both..Zootoxin
So to be clear: You can't set up a 32 bit PostgreSQL ODBC connection through the normal Windows GUI on a 64 bit system. You instead need to close the ODBC Data Source Administrator (if it's currently open), run c:\windows\sysWOW64\odbcad32.exe and configure the connection from there. Then you can later use that connection in a 32 bit program to access the database.Dihydric
Correct though I have set up the same information in both environments with success. Also, though it likely isn't a problem, you need to make sure that any middleware/clientware needed is also 32 and 64. For the stuff I've used, when you install the 64, you get 32 as well. If you're using Oracle, the (64b) 12c and 11g client will install a start link to the one in sysWOW64.Zootoxin
O
28

You get this exact same error when trying to connect to a MySQL database from MS-Access when the bit version (32 vs 64) of Access doesn't match

  1. the bit version of the ODBC Driver you are using
  2. the bit version of the ODBC Manager you used to set it up.

For those of you trying to connect MS-Access to MySQL on a 64 bit Windows system, I went through sheer torture trying to get it to work with both MS-Access 2010 and MS-Access 2013. Finally got it working, and here are the lessons I've learned along the way:

I bought a new Windows 7, 64 bit laptop, and I have an app which relies on MS-Access using MySQL tables.

  1. I installed the latest version of MySQL, 5.6, using the All In One package install. This allows you to install both the database and ODBC drivers all at once. That's nice, but the ODBC driver it installs seems to be the 64 bit one, so it will not work with 32 bit MS-Access. It also seems a little buggy - not for sure on that one. When you Add a new DSN in the ODBC Manager, this driver appears as "Microsoft ODBC For Oracle". I could not get this one to work. I had to install the 32 bit one, discussed below.

    • MySQL was working fine after the install. I restored my application MySQL database in the usual way. Now I want to connect to it using MS-Access.


  2. I had previously installed Office 2013, which I assumed was 64 bit. But upon checking the version (File, Account, About Access), I see that it is 32 bit. Both Access 2010 and 2013 are most commonly sold as 32-bit versions.

  3. My machine is a 64 bit machine. So by default, when you go to set up your DSN's for MS-Access, and go in the usual way into the ODBC Manager via Control Panel, Administrative Options, you get the 64 bit ODBC manager. You have no way of knowing that! You just can't tell. This is a huge gotcha!! It is impossible to set up a DSN from there and have it successfully connect to MS Access 32 bit. You will get the dreaded error:

    "the specified dsn contains an architecture mismatch..."

  4. You must download and install the 32 bit ODBC driver from MySQL. I used version 3.5.1

    http://dev.mysql.com/downloads/connector/odbc/3.51.html

  5. You must tell the ODBC Manager in Control Panel to take a hike and must instead explicitly invoke the 32 bit ODBC Manager with this command executed at the Start, Command prompt:

    c:\windows\sysWOW64\odbcad32.exe

    I created a shortcut to this on my desktop. From here, build your DSN with this manager. Important point: BUILD THEM AS SYSTEM DSNS, NOT USER DSNS! This tripped me up for awhile.

    By the way, the 64 bit version of the ODBC Manager can also be run explicitly as:

    c:\windows\system32\odbcad32.exe

  6. Once you've installed the 32-bit ODBC Driver from MySql, when you click Add in the ODBC Manager you will see 2 drivers listed. Choose "MySQL ODBC 5.2 ANSI Driver". I did not try the UNICODE driver.


That does it. Once you have defined your DSN's in the 32 bit ODBC manager, you can connect to MySQL in the usual way from within Access - External Data, ODBC Database, Link to the Database, select Machine Data Source, and the DSN you created to your MySQL database will be there.

Overcasting answered 22/6, 2013 at 1:36 Comment(2)
I think you switched around the paths for the two ODBC Managers 32 bit: c:\windows\system32\odbcad32.exe 64 bit: c:\windows\sysWOW64\odbcad32.exeUlrica
@Ulrica No, they're not switched. sysWOW64 is actually the 32-bit directory. Windows loves to be confusing. You will know which version you are using because it will show (32-bit) or (64-bit) in the title bar of the ODBC Data Source Administrator.Euphorbiaceous
E
8

There's an architecture mismatch. Your JDBC Driver and your JDK should be of the same architecture. If your using 32bit Driver and your JDK is 64bits, you would get that error.

See this

Fix : Depends on your architecture.

You will need 64-bit drivers if your Java is 64-bit.

Download : http://www.microsoft.com/downloads/details.aspx?familyid=C06B8369-60DD-4B64-A44B-84B371EDE16D&displaylang=en

Economic answered 17/1, 2012 at 14:7 Comment(1)
i've downloaded it and tried the new connection string as was specified in the instructions but it still didn't work. Maybe I'm doing something wrong?Wilt
G
3

To solve this problem first make sure that your java software should be 32bit version if it is 64 bit version clearly it will show the mismatch error so try to re-install 32bit of java version And execute the java program in the command of c:\windows\sysWOW64\odbcad32.exe (easiest to copy and paste into run dialog) that's enough your program definitely work

Gant answered 12/3, 2016 at 12:18 Comment(0)
M
2

By default, the Command Prompt is connected to System32. Run a 64-bit command prompt, i.e., C:\WINDOWS\SYSWOW64\CMD.EXE. In that, compile and run your java application.

Metametabel answered 8/7, 2012 at 5:28 Comment(0)
T
2

I saw this answer and it worked for me. https://msdn.microsoft.com/en-us/library/ms712362%28v=vs.85%29.aspx

After you have installed an ODBC driver from the driver's setup program, you can define one or more data sources for it. The data source name (DSN) should provide a unique description of the data; for example, Payroll or Accounts Payable. The user and system data sources that are defined for all currently installed drivers are listed in the User DSN or System DSN tabs of the ODBC Data Source Administrator dialog box. The file data sources in a given directory are listed in the File DSN tab; the directory to be shown is entered in the Look in box in the File DSN tab. System_CAPS_noteNote

To manage a data source that connects to a 32-bit driver under 64-bit platform, use c:\windows\sysWOW64\odbcad32.exe. To manage a data source that connects to a 64-bit driver, use c:\windows\system32\odbcad32.exe. In Administrative Tools on a 64-bit Windows 8 operating system, there are icons for both the 32-bit and 64-bit ODBC Data Source Administrator dialog box.

If you use the 64-bit odbcad32.exe to configure or remove a DSN that connects to a 32-bit driver, for example, Driver do Microsoft Access (*.mdb), you will receive the following error message:

The specified DSN contains an architecture mismatch between the Driver and Application

To resolve this error, use the 32-bit odbcad32.exe to configure or remove the DSN.

A data source associates a particular ODBC driver with the data you want to access through that driver. For example, you might create a data source to use the ODBC dBASE driver to access one or more dBASE files found in a specific directory on your hard disk or a network drive. Using the ODBC Data Source Administrator, you can add, modify, and delete data sources, as described in the following table.

Tonneson answered 7/12, 2015 at 11:1 Comment(1)
Hi Bineesh Kumar could your please explain breaflyGant
H
1

The problem you were facing might be because: you were having Office 32 bit and Command Prompt 64 bit. To solve the problem you need to follow 2 steps:

  1. Open ODBC Manager for DSN using: C:\Windows\SysWOW64\odbcad32.exe This will open the ODBC Data Administrator for 32 bit version and you will see all the database drivers.

  2. After this you need to open the 32 bit command prompt using: C:\Windows\SysWOW64\cmd.exe This will open the 32 bit version of command prompt. In this new CMD please recompile your Java program and run your program.

Hope this will help.

Havenot answered 26/12, 2012 at 17:40 Comment(0)
C
1

A little late, but since I've run into the same problem, in your exact scenario, I figured I'd add my solution.

I have Windows 7 (64-bit) and Office 2010 (32-bit). I tried with the DSN-less connection string:

jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=I:/TeamForge/ORS/CTFORS.accdb

and I tried with the DSN connection, using both the System32 and SysWOW64 versions of the ODBC Admin, and none of that worked.

What finally worked, was to match the bit version of Java with the bit version of Office. Once I did that, I could use either the DSN or DSN less connection mode, without any fuss.

Casa answered 18/5, 2013 at 22:13 Comment(1)
I implied this from Mob's answer, but thanks for confirming. What a mess!Lit
E
0

Have you created the DSN first in Control Panel>Administrative Tools>ODBC>System DSN. Name it same as "myDatabase" and if i is asking for locating the database/access file specify the path using browse option. Once ur DSN will be created successfully you will be easily able to access ur DB.

Ellen answered 17/1, 2012 at 14:9 Comment(7)
I created my DSN with the ODBC i found in C:\Windows\SysWOW64... The one in the control panel had nearly not drivers save the ones for sql server.Wilt
then you must install the drivers because without those drivers you cannot make ODBC connection.Ellen
do you have a link to these drivers? I've tried installing some but they didn't work.Wilt
microsoft.com/download/en/details.aspx?id=13255, microsoft.com/download/en/details.aspx?id=23734Ellen
I downloaded these and substituted the connection string: Connection dbConnection = DriverManager.getConnection("Driver={Microsoft Access Driver(*.mdb, *.accdb)};DBQ=C:\\Users\\Owner\\Documents\\myDatabase.mdb","admin",""); but its still giving me trouble. Maybe I need to change something else in the code?Wilt
have u provided the username when you created this access file, if not then (url,"","") for no username & password.Ellen
just tried it, no go. java.sql.SQLException: No suitable driver found for Driver={Microsoft Access Driver(*.mdb, *.accdb)};DBQ=C:\Users\Owner\Documents\myDatabase.mdbWilt
A
0

If you are using netbeans go to tools-> java Platform, change jdk_home which points to c:/programfiles/java/jdk1_7 to c:programFiles(x86)/java/jdk1_6_21

if not editable find netbeans.cnf and make change as stated abouve for jdk_home. restart neatbeans and how it works I had the same problem , but i worked .

Abyssal answered 7/6, 2012 at 4:46 Comment(0)
C
0

I had a great deal of trouble linking to MySQL from a 64 bit laptop, running Windows 7, using MS Access 2010. I found the previous article very helpful, but still could not connect using odbc 3.5.1. As I had previously linked a 32 bit machine using Connector/ODBC 5.1.13, I downloaded that version and set it up using the instructions above. Success. The answer seems to be to try different versions of Connector.odbc.

Chilli answered 29/12, 2013 at 20:59 Comment(0)
G
0

If you are connecting from a 64-bit platform using a 32-bit driver, then run the executable C:\Windows\SysWOW64\odbcad32.exe and create the DSN. It will work.

Gunshot answered 4/4, 2014 at 17:30 Comment(0)
D
0

I ran into this problem when upgrading to a windows 7 server with some legacy CLASP applications. Trying to run a 32bit application on a 64 bit machine.

Try setting the application pools 32bit compatibility to True and/or create dsn's in 32 and 64 bit.

Open the odbc datasource window in both versions from the run box. C:\Windows\SysWOW64\odbcad32.exe C:\Windows\system32\odbcad32.exe

Depress answered 21/4, 2014 at 21:28 Comment(0)
C
0

Go to this link and download ODBC Driver for 64 bits OS.

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

Catamnesis answered 25/4, 2014 at 17:56 Comment(0)
E
0

I did encounter this problem. This is due to you computer architecture and the database architecture you are using.

If you're using 32 bits operating system then everything works well because you can only install 32 bits software. Problem comes when you're using the 64 bits operating system.

In order to solve this problem is simple - I took long time to discover this issue.

  1. Knowing your Operating System is 64 bits but your Microsoft Office is 32 bits.
  2. So in order for you to access your database using NetBean IDE (assuming you're using this), you need to install 32 bits JDK. If you have installed 64 bits, you have to uninstall it and install the 32 bits.

You're unable to access your database because your 64 bits JVM is not the same as 32 bit JVM.

To add your database into your system 1. Control Panel 2. Administrator Tools 3. Data Source (ODBC) right click on it change the target to \sysWOW64\odbcad32.exe change the start in to r%\SysWOW64

Then you should be able to run. Inform me if you have any problem with this.

Thank you!

Endrin answered 7/7, 2014 at 3:59 Comment(0)
S
0

I have fixed the error.

Follow the steps:

  1. Install JDK of 32bt version
  2. Install MS-Office 2007
  3. Configure Control Panel : a. Control Panel b. Administrator Tools c. Data Source (ODBC)

    right click on it change the target to \sysWOW64\odbcad32.exe change the start in to r%\SysWOW64

Execute it and Best Luck. Works in windows 7 as well as 8

Remove Newer version of MS-Office and install only MS-Office 2007 if problem still persists

Sandry answered 13/2, 2015 at 7:29 Comment(0)
R
0

To solve this problem first make sure that your java software should be 32bit version if it is 64 bit version clearly it will show the mismatch error so try to re-install 32bit of java version And execute the java program in the command of c:\windows\sysWOW64\odbcad32.exe (easiest to copy and paste into run dialog) that's enough your program definitely work

Retainer answered 16/2, 2015 at 10:34 Comment(0)
E
0

i think this also will be more helpfull.

for the architecture miss match,

i just copy the jdk file from the 32 bit file ‪C:\Program Files (x86)\Java\jdk1.7.0_71 and paste it to the 64 bit file ‪C:\Program Files\Java\jdk1.7.0_10, then rename the file to match the file you replace to avoid the IDE error(netbeans)

then your good to go.

note: You should buckup you 64bit files so when you want to create 64 bit application you can return it to its location

Eogene answered 2/7, 2015 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.