如何将java连接到Ms Access 2010?
有谁知道如何将 Access 2010 连接到 java jdbc。我使用这个方法,但是当我调用它时,它不起作用:
public void loadDb(){
try{
Class.forName("sun.jdbc.JdbcOdbcDriver");
File f = new File(System.getProperty("user.dir"))
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Acess Driver (*.mdb, *.accdb)}; DBQ="+ f.getPath() + "//db//JavaAccess.accd","","");
st = con. createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
}catch(ClassNotFoundException e){e.printStackTrace();
}catch(SQLException e){e.printStackTrace();}
}
//con and st are already defined
Does anyone have any ideas of how to connect Access 2010 to java jdbc. I use this method, but when I call it, it doesn't work:
public void loadDb(){
try{
Class.forName("sun.jdbc.JdbcOdbcDriver");
File f = new File(System.getProperty("user.dir"))
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Acess Driver (*.mdb, *.accdb)}; DBQ="+ f.getPath() + "//db//JavaAccess.accd","","");
st = con. createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
}catch(ClassNotFoundException e){e.printStackTrace();
}catch(SQLException e){e.printStackTrace();}
}
//con and st are already defined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据 msdn 它应该是
sun.jdbc.odbc.JdbcOdbcDriver
。因此替换这行代码:Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
According to msdn it should be
sun.jdbc.odbc.JdbcOdbcDriver
. So replace this line of code:Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
拼写错误?也许这一行:
应该是
Access 有 2 个 C
Spelling error? Perhaps this line:
should be
Access has 2 C's
创建连接
如何调用:
Create connection
How to call:
使用 UCanAccess JDBC 驱动程序:
例如:
所以对于您的示例来说,它将是
Use UCanAccess JDBC Driver :
e.g.:
So for your example it will be
Rishab 的回复帮助我连接到我的访问数据库。
我在代码中做了以下更正:
明确
我没有
定义驱动程序和带有路径和扩展名的完整数据库名称。
Rishab's reply helped me to connect to my access database.
I did following correction in the code:
Instead of
I did
I explicitly defined driver and full database name with path and extension.
就像今天一样,我们遇到了同样的问题,发现要检查java的版本,如果你的
java 版本 如果 java 版本高于 7,则不支持 sun.jdbc.odbc.JdbcOdbcDriver,因此只需检查 java 版本即可。
As today only we face the same problem and found that to check the version of java if your
version of java if the version of the java is above 7 then the sun.jdbc.odbc.JdbcOdbcDriver will not be supported so just check the version of the java.