指定的DSN包含驱动程序和应用程序之间的体系结构不匹配。 JAVA [英] The specified DSN contains an architecture mismatch between the Driver and Application. JAVA

查看:192
本文介绍了指定的DSN包含驱动程序和应用程序之间的体系结构不匹配。 JAVA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java连接到MS Access创建的数据库,但我似乎无法管理。我正在使用ODBC,我得到了这个异常:

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驱动程序管理器]指定的DSN包含一个体系结构不匹配驱动程序和应用程序

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

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


推荐答案

这些都不是为我做的。我确实在MSDN上找到了答案。但有一些暗示。错误中的体系结构是指32比64位。我的解决方案是找出我的应用程序在(Access)下运行的哪个2010是32b。我通过查看任务管理器的进程选项卡找到了这一点,其中所有32b进程都有* 32名称的结尾。如前所述,控制面板将从此处启动 64 位版本的ODBC

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

和32位版本在这里:

c:\windows \ sysWOW64 \odbcad32.exe (最容易复制并粘贴到运行对话框中)

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

因此,我在每个指向同一事物的相应ODBC控制面板(AKA管理员)中设置名称以32和64结尾的DSN。然后,我根据使用它的应用程序是32b还是64b来挑选/选择正确的。

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.

这篇关于指定的DSN包含驱动程序和应用程序之间的体系结构不匹配。 JAVA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆