Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未找到数据源名称,未指定默认驱动程序_Java_Odbc - Fatal编程技术网

Java 未找到数据源名称,未指定默认驱动程序

Java 未找到数据源名称,未指定默认驱动程序,java,odbc,Java,Odbc,我正在尝试从Java应用程序连接到MS Access数据库。这是我的代码: try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // set this to a MS Access DB you have on your machine String filename = "UserInformation.accdb"; String database = "jdbc:odbc:Driver={Microsoft Access Driver

我正在尝试从Java应用程序连接到MS Access数据库。这是我的代码:

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "UserInformation.accdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
Statement st= con.createStatement();
int i=st.executeUpdate("insert into Users(User_Name,User_Password)             values('"+username+"','"+password+"')");
System.out.println("Row is added");
}catch (Exception e) {
System.out.println("Error: " + e);
}
我得到这个异常:找不到数据源名称,并且没有指定默认驱动程序ODBC

我怎样才能修好它


提前感谢

可能是几件事。我在从64位桌面上的32位计算机上入侵数据库时遇到了这个问题

如果您在Java中使用32位与64位的odbc搜索问题,您将看到大量的资料。最终对我起作用的是从Java5切换到Java6,并确保我的Eclipse运行时配置没有设置不兼容的位模式


抱歉说得有点含糊,但在花了几个小时试图弄清楚之后,我相信这可能是非常依赖于情景的。

可能是几件事。我在从64位桌面上的32位计算机上入侵数据库时遇到了这个问题

如果您在Java中使用32位与64位的odbc搜索问题,您将看到大量的资料。最终对我起作用的是从Java5切换到Java6,并确保我的Eclipse运行时配置没有设置不兼容的位模式


抱歉说得有点含糊,但在花了几个小时试图弄清楚之后,我相信这可能是非常依赖于情况的。

如果我没有弄错的话,您必须指定数据库文件的完整路径,例如:jdbc:odbc:Driver={Microsoft Access Driver*.accdb};DBQ=c:\my\database\UserInformation.accdb;DriverID=22;我已经试过了。我也把数据库放在我的项目文件夹中。现在我找不到合适的驱动程序。我希望你的系统上安装了MS Access驱动程序。你解决过这个问题吗?如果我没有弄错,你必须指定数据库文件的完整路径,例如:jdbc:odbc:driver={Microsoft Access driver*.accdb};DBQ=c:\my\database\UserInformation.accdb;DriverID=22;我已经试过了。我也把我的数据库放在我的项目文件夹中。现在我找不到合适的驱动程序。我希望你的系统上安装了MS Access驱动程序。你解决过这个问题吗?