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

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

问题描述

我正在尝试连接到 MS Access 使用 Java 制作的数据库,但我似乎无法进行管理.我正在使用 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 Driver Manager] 指定的 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:windowssystem32odbcad32.exe

32 位版本在这里:

c:windowssysWOW64odbcad32.exe(最容易复制粘贴到运行对话框中)

c:windowssysWOW64odbcad32.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 包含驱动程序和应用程序之间的体系结构不匹配.爪哇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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