java.sql.SQLException 找不到适合 jdbc:odbc:man 的驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27809448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:25:50  来源:igfitidea点击:

java.sql.SQLException No suitable drivers found for jdbc:odbc:man

javajdbcodbcms-access-2013

提问by Senthil Vidhiyakar

I am a beginner in Java having only limited knowledge in SQL commands say 5 or 6 commands... I tried connecting my Java project with an access database "aman.accdb" using ODBC in my laptop.. The database has a table named "tab".. I am using a windows 7 64 bit pc with Java JDK for 64 bit installed in it. And also I use ms office 2013 which is also a 64 bit product.

我是 Java 初学者,对 SQL 命令只有有限的知识,比如 5 或 6 个命令......我尝试在我的笔记本电脑中使用 ODBC 将我的 Java 项目与访问数据库“aman.accdb”连接起来。该数据库有一个名为“的表”选项卡”..我正在使用装有 Java JDK 的 Windows 7 64 位电脑,其中安装了 64 位。我还使用 ms office 2013,它也是 64 位产品。

When I executed the code an error " java.sql.SQLException No suitable drivers found for jdbc:odbc:man" I am posting the sample code which caused an error below. I have removed the unwanted lines such as layout setting and all as it runs for pages.

当我执行代码时出现错误“java.sql.SQLException 未找到适用于 jdbc:odbc:man 的合适驱动程序”我发布了导致以下错误的示例代码。我已经删除了不需要的行,例如布局设置以及它为页面运行的所有内容。

Please provide a solution to this!

请提供解决方案!

package sample;

import java.sql.*;

import javax.swing.JOptionPane;

public class als extends javax.swing.JFrame {

    public als() throws SQLException {

        initComponents();

        try
        {
        con=DriverManager.getConnection("jdbc:odbc:man") ;
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Check");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });



    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        try
        {
          st=con.createStatement();
           String s=("insert into tab ('senthil',12)");
          st.execute(s);
             JOptionPane.showMessageDialog(rootPane,"Saved");
             this.setVisible(false);
            }catch(Exception e)
            {
                JOptionPane.showMessageDialog(rootPane,e);
            }
    }                                        


    static Connection con;
    static Statement st;
    static ResultSet rs;
    private javax.swing.JButton jButton1;                  
}

I came to know that this problem occurs in 64 bit OS oly.. Will this not happen if I install a 32 bit OS.

我开始知道这个问题发生在 64 位操作系统中。如果我安装 32 位操作系统,这会不会发生。

Note : The error I got is an exception which I displayed through a message box in catch()part in constructor als().

注意:我得到的错误是我catch()在构造函数中通过消息框显示的一个异常als()

回答by Gord Thompson

I am using JDK 1.8.0

我正在使用 JDK 1.8.0

The JDBC-ODBC Bridge has been removed from Java 8. Consider using the UCanAccessJDBC driver instead. For details. see

JDBC-ODBC Bridge 已从 Java 8 中删除。请考虑改用UCanAccessJDBC 驱动程序。欲知详情。看

Manipulating an Access database from Java without ODBC

在没有 ODBC 的情况下从 Java 操作 Access 数据库

回答by Voqus

Try this, i believe its because you have not specified the driver. This is for MS Accessdatabase.

试试这个,我相信这是因为你没有指定驱动程序。这是用于MS Access数据库。

public als() throws SQLException {

    initComponents();

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:man") ;
    }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e);
    }
}