Microsoft Access和Java JDBC-ODBC错误 [英] Microsoft Access and Java JDBC-ODBC Error

查看:219
本文介绍了Microsoft Access和Java JDBC-ODBC错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用java在Microsoft访问数据库中插入一些值。

Trying to insert some values in a Microsoft access database using java.

但我可能会出错,

java.sql.SQLException:[Microsoft] [ODBC驱动程序管理器]指定的
DSN在线程mainjava中包含驱动程序和
应用程序异常之间的体系结构不匹配.lang.NullPointerException

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application Exception in thread "main" java.lang.NullPointerException

使用SysWoW64创建数据源> odbcad32并将数据源添加到系统DNS。我说这是因为我已经看到64位系统出现问题。但它仍然不适用于我。

To create the data source im using SysWoW64 > odbcad32 and adding it the datasource to system DNS. I say this as i have seen else where there are problems which occur with 64bit systems. However it still doesn't work for me.

Microsoft Office 32位。

Microsoft Office 32bit.

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


public class AuctionHouseJDBC {

    /**
     * @param args
     */
    public static void main(String[] args) {

        String theItem = "Car";
        String theClient="Name";
        String theMessage="1001";



Connection conn =null; // Create connection object

        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            System.out.println("Driver Found");
        } catch(Exception e) {
            System.out.println("Driver Not Found");
            System.err.println(e);
        }

        // connecting to database
        try{
            String database ="jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)};DBQ=AuctionHouseDatabase.accdb;";

            conn = DriverManager.getConnection(database,"","");

            System.out.println("Conn Found");
        }
        catch(SQLException se) {
            System.out.println("Conn Not Found");
            System.err.println(se);
        }
        // Create select statement and execute it

        try{        
            /*String insertSQL = "INSERT INTO AuctionHouse VALUES (  "
                    +"'" +theItem+"', "  
                    +"'" +theClient+"', "
                    +"'" +theMessage+"')";  
            */

            Statement stmt = conn.createStatement();
            String insertSQL = "Insert into AuctionHouse VALUES ('Item','Name','Price')";

             stmt.executeUpdate(insertSQL);
            // Retrieve the results

            conn.close();
        } catch(SQLException se) {
            System.out.println("SqlStatment Not Found");
            System.err.println(se);
        }

    }

}

StaceTrace:

StaceTrace:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)

Microsoft Office 64位

Microsoft Office 64bit

我安装了64位版本,现在我发现错误[Microsoft] [ODBC驱动程序管理器]不是有效的文件名。

Ive installed 64 bit version and now im gettin an error [Microsoft][ODBC Driver Manager] Not a valid file name.

推荐答案

首先确保您可以通过ODBC访问该数据库。为64位和32位系统在 odbcad32 中创建DSN。然后作为JDBC连接字符串使用: jdbc:odbc:[CreatedDSN] 。如果您无法连接到64位版本的 odbcad32 中的Access,请确保它在32位版本的 odbcad32 中工作,并且确保使用32位版本的Java。

At first make sure you can access that database via ODBC. Make DSN in odbcad32 for both 64 and 32 bit systems. Then as JDBC connect string use: jdbc:odbc:[CreatedDSN]. If you cannot connect to Access in 64 bit version of odbcad32 then make sure it works in 32 bit version of odbcad32 and make sure you use 32 bit version of Java.

还要查看其他响应:无法使用Windows-64bit连接到MS Access DB

特别有趣的链接到: http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/

这篇关于Microsoft Access和Java JDBC-ODBC错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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