【问题标题】:how to avoid java.sql.SQLException:[Microsoft][ODBC Microsoft Access Driver] could not find file '(unkown)'如何避免 java.sql.SQLException:[Microsoft][ODBC Microsoft Access Driver] 找不到文件“(未知)”
【发布时间】:2014-04-25 00:50:16
【问题描述】:

我在 windows 7 上使用 java se 和 microsoft access /jet 数据库。在使用 windows 7 之前,我使用的是 win xp。用eclipse写代码,在ms access 2007上建数据库,用odbc-system dsn建立连接。在 win xp 上,我的数据库连接工作正常,我在 java 上的导航控件看起来很完美,但在 windows 7 上它提示错误:

java.sql.SQLException:[Microsoft][ODBC Microsoft Access Driver] could not find file '(unknown)'.

我已经在c:windows\syswow64 上添加了 32 位 odbc 并在管理工具/odbc 中建立了连接,但仍然提示我该错误。我错过了什么?

【问题讨论】:

    标签: java sql windows-7 odbc 32bit-64bit


    【解决方案1】:

    您必须在管理工具中添加 Microsoft Access Driver。

    如果这不起作用:

    try
    {
      //your code
    } 
    catch(Exception ex)
    {
    
    }
    

    这是我的代码:

    public void dbconnect1(){
        try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        condb1 = DriverManager.getConnection("jdbc:odbc:Datab1");
        stdb1 = condb1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
        String sql = "Select * from Table1";
        rsdb1 = stdb1.executeQuery(sql);
    
        if (rsdb1.next()){
        textid.setText(rsdb1.getString("id"));
        textfn.setText(rsdb1.getString("fn"));
        textln.setText(rsdb1.getString("ln"));
        textdep.setText(rsdb1.getString("dept"));
        textpos.setText(rsdb1.getString("position"));
        textyearh.setText(rsdb1.getString("yearhired"));
    
        } else {JOptionPane.showMessageDialog(null,"connection in charge");}
    
    
        } catch (Exception ex){JOptionPane.showMessageDialog(null,"error connect"+ex);}
    
    }
    

    【讨论】:

    • 您是否打印了异常错误?如果有,他们怎么说?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多