try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database =
"jdbc:odbc:Driver={MS Access Database (*.accdb)};DBQ=obn.accdb;";
c= DriverManager.getConnection(database, "", "");
s=c.createStatement();
string = "IN TRY";
s.close(); // Close the statement
c.close(); // Close the database. Its no more required
JOptionPane.showMessageDialog(null, string);
}
catch(Exception e)
{
string = "IN exception";
JOptionPane.showMessageDialog(null, string);
}
我尝试访问使用Java的MS Access数据库使用上述代码总是有一个例外。我已经尝试了一些东西使用Java访问MS Access数据库
c= DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=obn.mdb");
s=c.createStatement();
在第一个和第二个我得到的例外 -
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
...
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c= DriverManager.getConnection("jdbc:odbc:obn");
s=c.createStatement();
试着这样做类似这样的,在加入OBN ODBC中的数据源(32位),选择数据库的路径。但它也没有工作。
它给错误
The specified DSN contains an architecture mismatch between the Driver and Application
我通常不使用的MS Access,但我必须为大学项目
驱动程序关键字语法错误是我什么时候得到我尝试 {Microsoft Access驱动程序(* .MDB,* .ACCDB)} 或 {Microsoft Access驱动程序(* .ACCDB)} – XuryaX
C =的DriverManager.getConnection( “JDBC:ODBC:OBN”); 我认为这里有64位,32位不匹配 – XuryaX