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
MS Access is a part of Microsoft Office and used as database management system (dbms). For making a new database go to MS Access > Blank Database. Give a name to database and click on Createbutton to create the database. Also Read: How to Connect Java (JDBC) with MySQL or Oracle Database Below example shows jdbc ms access database connectivity.
There are a number of errors, though, if you attempt to use a 64-bit version of Java that are not as well documented. This article points out some of those issues and a working strategy for how to successfully connect to a Microsoft Access file via JDBC in 64-bit Java.
In order to connect to an Access database, you must first install the Microsoft Access Driver. If you're on Windows, you can do this by either installing Access or installing the Access Database Engine. Whichever product you install, you must make sure that the architecture matches your JVM.
To connect your java program with the MS Access database in Eclipse IDE, you need to include UCanAccess Jar files to the Eclipse. I have given the download link of the zip file in the above. Extract the zip archive and you will get the Jar files.
According to msdn it should be sun.jdbc.odbc.JdbcOdbcDriver
. So replace this line of code:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Spelling error? Perhaps this line:
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Acess Driver (*.mdb, *.accdb)}; DBQ="+ f.getPath() + "//db//JavaAccess.accd","","");
should be
con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ="+ f.getPath() + "//db//JavaAccess.accd","","");
Access has 2 C's
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With