简体   繁体   English

MS ACCESS jdbc.odbc连接。 找不到数据源名称/未指定默认驱动程序?

[英]MS ACCESS jdbc.odbc connection. data source name not found/No default driver specified?

I'm trying to study for a basic SQL test at school but unfortunately I copied the class that we are supposed to use into a project on my pc and I am getting the following error: 我正在尝试在学校学习基本的SQL测试,但不幸的是,我将本应使用的类复制到PC上的项目中,并且遇到以下错误:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified java.sql.SQLException:[Microsoft] [ODBC驱动程序管理器]找不到数据源名称,未指定默认驱动程序

package Question1;

// Your name, Q 1
import java.sql.*;
import java.io.*;
import javax.swing.*;

public class GreenWood
{
 // Set up database connection
   private static final String DATABASE_FILE_NAME = "WoodDB.mdb";
   private static final String DRIVER = "jdbc:odbc:DRIVER=" +
   "{Microsoft Access Driver (*.mdb)};" +
   "DBQ=" + new File (DATABASE_FILE_NAME).getAbsolutePath ();
  static
  {
     try
     {
        Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
     }
         catch (ClassNotFoundException e)
        {
           System.out.println ("Class not found");
           e.printStackTrace ();
        }
  }


  private Connection dbcon;
  private BufferedReader keyb = new BufferedReader (new InputStreamReader (System.in));

   public GreenWood ()
  {
     System.out.println ("WoodDB Connection");
     try
     {
        dbcon = DriverManager.getConnection (DRIVER);
        Statement stmt = dbcon.createStatement ();
        System.out.println ("Connection successful\n");

        char choice = ' ';
        do
        {

         //Prints options for user input

           choice = keyb.readLine ().toUpperCase ().charAt (0);
           System.out.println (" ");
           switch (choice)
           {
             //calls query methods based on user input

           }
        }
        while (choice != 'X');
        dbcon.close ();
        System.out.println ("Done");
        Thread.sleep (1000);
        System.exit (0);
     } // try
         catch (Exception e)
        {
        // process exceptions here
           System.out.println ("Connection unsuccessful");
           e.printStackTrace ();
           System.out.println (e.toString ());
        }
  } // HoutSoorte constructor

  //Query Methods
  //Main creates new instance of GreenWood

my WoodDB database is located in the root project directory. 我的WoodDB数据库位于项目根目录中。

I Have done some troubleshooting and I believe that the problem is the URL of the driver location; 我已经进行了一些故障排除,我相信问题出在驱动程序位置的URL。

dbcon = DriverManager.getConnection (DRIVER);

DRIVER being: 驱动因素是:

private static final String DRIVER = "jdbc:odbc:DRIVER=" +
   "{Microsoft Access Driver (*.mdb)};" +
   "DBQ=" + new File (DATABASE_FILE_NAME).getAbsolutePath ();

After about an hour of research I'm still just as confused as I was. 经过大约一个小时的研究,我仍然和以前一样困惑。 If anyone can help this nub programmer(me) by explaining the problem in baby words and how I can fix it, it would be ever appreciated. 如果有人能用婴儿的语言解释问题以及我如何解决这个问题,可以帮助这个nub程序员,那么我将不胜感激。

Try using 32-bit JVM. 尝试使用32位JVM。 I am getting the same error message when trying to connect from 64-bit JVM. 尝试从64位JVM连接时,出现相同的错误消息。

Try the following if it works: 如果可行,请尝试以下方法:

For 64 bit system, Goto: C:\\windows\\sysWOW64. 对于64位系统,请转到:C:\\ windows \\ sysWOW64。 For 32 bit system, Goto: C:\\windows 对于32位系统,转到:C:\\ windows

There is an executable called odbcad32.exe. 有一个名为odbcad32.exe的可执行文件。

Run this exe as administrator to gain access to all the ODBC drivers that come with Microsoft Office, etc. 以管理员身份运行此exe文件,以访问Microsoft Office等随附的所有ODBC驱动程序。

Create data source named my_data_source and mention the connection string as: 创建名为my_data_source的数据源,并将连接字符串提及为:

Connection con = DriverManager.getConnection("jdbc:odbc:my_data_source"); 连接con = DriverManager.getConnection(“ jdbc:odbc:my_data_source”);

Above solution worked in my case. 以上解决方案在我的情况下有效。

Please refer: Java Connectivity with MS Access for details. 请参考: 带有MS Access的Java连接了解详细信息。

尝试使用DATABASE_FILE的完整路径名或将其复制到源目录中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到JDBC / ODBC数据源名称,也未指定默认驱动程序 - JDBC/ODBC Data source name not found and no default driver specified [Microsoft] [ODBC驱动程序管理器]找不到数据源名称且未指定默认驱动程序-在IDE中工作正常-一次没有导出 - [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified - works fine in IDE - not once exported 数据库 - [Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序 - Database - [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 如何解析[Microsoft] [ODBC Driver Manager]数据源名称未找到且未指定默认驱动程序 - How to resolve [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified java.sql.SQLException:[Microsoft] [ODBC驱动程序管理器]找不到数据源名称,未指定默认驱动程序 - java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 找不到数据源名称,也未指定默认驱动程序 - Data Source Name Not Found And No Default Driver Specified 错误:无法连接到[Microsoft] [ODBC管理器]数据源名称未找到且未指定默认驱动程序 - Error: Cannot connect to [Microsoft][ODBC Manager] Data source name not found and no default driver specified 尝试连接到MS Excel 2007 [无法创建DSN]-错误:找不到数据源名称,并且未指定默认驱动程序 - Trying to connect to MS Excel 2007 [wtihout creating DSN] - Error: Data source name not found and no default driver specified 无法连接到数据库错误:java.sql.SQLException:[Microsoft] [ODBC驱动程序管理器]找不到数据源名称并且未指定默认驱动程序 - Cannot connect to database Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 我没有找到数据源名称并且没有指定默认驱动程序 - I got Data source name not found and no default driver specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM