简体   繁体   English

Java访问数据库连接失败?

[英]Java connection to access database fails?

Iam using windows 8.1 (64 bit) with microsoft office 32bit version. Iam使用Windows 8.1(64位)和Microsoft Office 32位版本。 Iam trying to connect to an access file to retrieve username and password but the connection to the access database cannot be made, I have searched alot on the internet but can't seem to find a solution for this problem. 我试图连接到访问文件以检索用户名和密码,但是无法建立与访问数据库的连接,我在互联网上进行了大量搜索,但似乎无法找到解决该问题的方法。 I downloaded office 64bit with Microsoft Access Database Engine 2010 Redistributable but I still get the same error. 我使用Microsoft Access Database Engine 2010 Redistributable下载了Office 64位,但仍然收到相同的错误。 What should I do to overcome this issue? 我应该怎么做才能克服这个问题?

Java method: Java方法:

dbcon()
{
try{     

   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   con=DriverManager.getConnection("jdbc:odbc:db5");

  }catch(Exception e){
   System.out.println(e);
 }
 }

Error: 错误:

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

This may be the fact that your ODBC driver is 32 bit, which can not be recognized by the 64 bit Java. 这可能是因为您的ODBC驱动程序是32位,但64位Java无法识别。 Either create a 64 bit ODBC driver or run Java in 32 bit mode (-D32 switch). 创建64位ODBC驱动程序或以32位模式(-D32开关)运行Java。

Try with the following connection string: 尝试使用以下连接字符串:

"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=full_path_to_your_db_file" “ jdbc:odbc:Driver = {Microsoft Access驱动程序(* .mdb,* .accdb)}; DBQ = full_path_to_your_db_file”

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM