Try connecting to via JDBC – ODBC in Java 8 Classnotfoundexception in accdb file
I am using a java project in the eclipse EE IDE and I have to query Accdb file
My code:
try{
String filePath = "//myfilepathtomydb/BLABLA/example.accdb"
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ=" + filePath;
Connection database = DriverManager.getConnection(url);
System.out.println("Connection sucessful");
} catch (ClassNotFoundException e){
System.err.println("Got an exception");
System.err.println(e.getMessage());
e.printStackTrace();
} catch (sqlException sqle) {
sqle.printStackTrace();
// TODO: handle exception
}
Exceptions:
Got an exception
sun.jdbc.odbc.JdbcOdbcDriver
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
at java.net.urlclassloader$1.run(urlclassloader.java:372)
at java.net.urlclassloader$1.run(urlclassloader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.urlclassloader.findClass(urlclassloader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at project.Main.main(Main.java:15)
I use 32-bit eclipse in 64 bit windows, and the way I read about connecting to the database does not support 64 bit JRE, so I use the selected 32-bit JRE (jdk1.8.0_05). In my running configuration, I use the '- D32' parameter in the VM
Obviously, the jdbcodbcdriver should be in rt.jar, but when I looked for it, I couldn't find the following package: sun jdbc. odbc. JdbcOdbcDriver.
I would appreciate it if someone could explain my problems, any mistakes or stupid things, and I said I could correct me at will
Solution
According to this post, jdbc-odbc bridge was deleted in Java 8 You can use JDBC drivers specifically for access I've seen many people mention that ucanaccess connects to access, although I don't use it myself
