I'm working in a project in Java in Eclipse EE IDE where I have to query a .accdb
file.
The problem is when I try to load the driver and then connect to the database it gives me an exception error.
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
}
The exception:
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'm using 32-bit Eclipse in a 64-bit Windows and from what i've read this way of connecting to the database is not supported by a 64-bit JRE, so I'm using a chosen 32-bit JRE (jdk1.8.0_05) and in my run configurations I used the '-d32' argument in VM.
Apparently the JdbcOdbcDriver
should be inside the rt.jar, but when i look for it i can't find the following package: sun.jdbc.odbc.JdbcOdbcDriver
.
Would be appreciated if someone could shed light to my problem, any mistakes or stupid things i said fell free to correct me also.