MS ACCESS jdbc.odbc连接。未找到数据源名称/未指定默认驱动程序? [英] MS ACCESS jdbc.odbc connection. data source name not found/No default driver specified?

查看:274
本文介绍了MS ACCESS jdbc.odbc连接。未找到数据源名称/未指定默认驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在学校学习一个基本的SQL测试,但不幸的是我把我们应该使用的类,我的电脑上的项目,我得到以下错误:




 包问题1; 

//你的名字,Q 1
import java.sql。*;
import java.io. *;
import javax.swing。*;

public class GreenWood
{
//设置数据库连接
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连接dbcon;
private BufferedReader keyb = new BufferedReader(new InputStreamReader(System.in));

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

char choice ='';
do
{

//打印用户输入的选项

choice = keyb.readLine().toUpperCase().charAt(0);
System.out.println();
switch(choice)
{
//根据用户输入调用查询方法

}
}
while(choice!=' X');
dbcon.close();
System.out.println(Done);
Thread.sleep(1000);
System.exit(0);
} // try
catch(Exception e)
{
//这里处理异常
System.out.println(Connection unsuccessful);
e.printStackTrace();
System.out.println(e.toString());
}
} // HoutSoorte构造函数

//查询方法
//主要创建GreenWood的新实例

我的WoodDB数据库位于根项目目录中。



我做了一些故障排除和相信问题是驱动程序位置的URL;

  dbcon = DriverManager.getConnection(DRIVER); 

DRIVER是:

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

经过约一个小时的研究后,我仍然像我一样困惑。
如果任何人可以帮助这个nub程序员(我)通过解释宝宝的话的问题,如何我可以解决它,这将是非常受欢迎。

解决方案

尝试使用32位JVM。我尝试从64位JVM连接时收到相同的错误消息。


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:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

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.

I Have done some troubleshooting and I believe that the problem is the URL of the driver location;

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.

解决方案

Try using 32-bit JVM. I am getting the same error message when trying to connect from 64-bit JVM.

这篇关于MS ACCESS jdbc.odbc连接。未找到数据源名称/未指定默认驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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