Java 如何解决 [Microsoft][ODBC 驱动程序管理器] 未找到数据源名称且未指定默认驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18599133/
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-08-12 09:22:20  来源:igfitidea点击:

How to resolve [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

javams-accessms-access-2010

提问by jadhavaniket008

I tried to make a connection with Access but I encountered the following problem after compiling my Java file

我试图与 Access 建立连接,但在编译我的 Java 文件后遇到以下问题

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

[Microsoft][ODBC 驱动程序管理器] 未找到数据源名称且未指定默认驱动程序

my code is :

我的代码是:

import java.sql.*;

public class abc
           {
            public static void main(String args[])
            {

             try 
                {
                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                 String fn="C:/ctb/new";
                 String database = "jdbc:odbc:Driver={Microsoft Access Driver                 (*.mdb,*.accdb)};DBQ="+fn+".accdb;";
                 Connection conn = DriverManager.getConnection(database); 
         System.out.println(conn);


                 }
            catch(Exception e)
                 {
                  e.printStackTrace();
                  System.out.println("Error!");
                 }
           }
     }

回答by Gord Thompson

When I copy and paste your code into Eclipse I get the error message you mention. That is because the driver name is malformed. Instead of...

当我将您的代码复制并粘贴到 Eclipse 中时,我收到了您提到的错误消息。那是因为驱动程序名称格式错误。代替...

String database = "jdbc:odbc:Driver={Microsoft Access Driver                 (*.mdb,*.accdb)};DBQ="+fn+".accdb;";

...you need to use...

......你需要使用......

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+fn+".accdb;";

Note the single spaces in ... Driver (*.mdb, *.accdb)...

注意中的单个空格 ... Driver (*.mdb, *.accdb)...