The specified DSN contains an architecture mismatc

2019-01-02 17:38发布

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);
        }
    }
}

标签: java odbc
18条回答
呛了眼睛熬了心
2楼-- · 2019-01-02 18:21

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

查看更多
若你有天会懂
3楼-- · 2019-01-02 18:24

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.

查看更多
高级女魔头
4楼-- · 2019-01-02 18:25

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

查看更多
一个人的天荒地老
5楼-- · 2019-01-02 18:26

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

查看更多
低头抚发
6楼-- · 2019-01-02 18:27

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.

查看更多
泪湿衣
7楼-- · 2019-01-02 18:27

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 .

查看更多
登录 后发表回答