如何将java连接到Ms Access 2010? [英] How to connect java to Ms Access 2010?

查看:132
本文介绍了如何将java连接到Ms Access 2010?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人对如何将Access 2010连接到java jdbc有任何想法。我使用这种方法,但是当我调用它时,它不起作用:

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


推荐答案

根据 msdn 它应该是 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);

这篇关于如何将java连接到Ms Access 2010?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆