JDBC驱动程序MS Access连接 [英] JDBC driver MS Access connection
问题描述
我希望用MS GUI程序连接我的MS访问文件,但我有连接问题....
I want connect my MS access file with Java GUI program,but I have problem with connection....
我有Windows 7 64b和ms office 2007 。
当我在控制面板中打开ODBC驱动程序管理器时,我没有找到任何Microsoft Access驱动程序(也许当我启动ODBC开始运行64位ODBC时,现在我认为运行32位ODBC。
我读了这个并且我做到了:
jdbc-odbc连接窗口7 64位机器..
1.右键单击数据源(ODBC)..转到属性更改下列事物
I have Windows 7 64b, and ms office 2007. When I opened the ODBC driver manager in the control panel I havent found any driver for Microsoft Access (maybe when I started the ODBC is started running the 64bit ODBC, now I think is running the 32bit ODBC. I read this and I make it : "jdbc-odbc connection for window 7 64 bit machine.. 1 . Right click Data source (ODBC)..go to properties change the folloing thing
目标[%SystemRoot%\ SysWOW64 \odbcad32.exe]
开始于:[%SystemRoot%\ System32]
target [ %SystemRoot%\SysWOW64\odbcad32.exe ] start in : [ %SystemRoot%\System32 ]
按回车并继续作为管理员来源: source link
)现在,当我在conctrol pannel中启动ODBC时,我可以看到驱动程序 screenshoot
press enter and continue as admin source: source link " ) Now when I start in conctrol pannel the ODBC I can see the driver screenshoot
我的程序代码(我试过两种方法,但我有同样的错误):
My program code(I tried two ways but I have same error):
public void Connect() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// String DatabaseFile = "D:java/Invertory.mdb";
// String DATABASE =
// "jdbc:odbc:Driver="
// + "{Microsoft Access Driver (*.mdb, *.accdb)};"
// + "DBQ=" + DatabaseFile;`enter code here`
String DATABASE ="jdbc:odbc:Driver= Microsoft Access Driver (*.mdb, *.accdb);DBQ=Invertory.mdb";
CONEX = DriverManager.getConnection(DATABASE);
} catch (Exception X) {
X.printStackTrace();
//JOptionPane.showMessageDialog(null,e);
}
}
错误
java.sql.SQLException:[Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
推荐答案
使用 UCanAccess JDBC驱动程序:
Use UCanAccess JDBC Driver :
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://<mdb or accdb file path>",user, password);
for example:
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://c:/pippo.mdb");
因此,对于您的示例,它将是 Connection conn = DriverManager.getConnection( jdbc:ucanaccess://+ path
So for your example it will be Connection conn=DriverManager.getConnection("jdbc:ucanaccess://"+path)
这篇关于JDBC驱动程序MS Access连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!