• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read MS Access files with Java - Hopeless?

 
Arie Kaufman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty new to Java and I'd like to be able to use my Ubuntu Computer to extract information from MS Access files (using sql statements)

Is that a hopeless venture?

I've already tried using code like this:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
import java.sql.*;
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=/home/stupiddatabase.mdb;";
Connection myConnection = DriverManager.getConnection(database,"","");
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

This, however, throws a ClassNotFoundException: "sun.jdbc.odbc.JdbcOdbcDriver"

So, I don't have that driver... ok. Obviously it didn't come with my Java 7 installation.

I've heard that I can find this odbc-driver in the jar-file rt.jar but the problem is that it seems to have disappeared from there some years ago from the jre version 1.6.0.

So here comes my newbee-questions:

Is it possible to download older versions of jar-files and use them in combination with new ones? Or can I extract certain java classes from old jar-files and use them i combination with the latest JRE?

I've just started using Eclipse btw.

Help and hints greatly appreciated

I've been using windows for many years and I think it would be great if it was possible to migrate over to Linux even though I still (because of my job) need to be able to deal with some MS-stuff like access-files.

Ps: I've seen something called Jackcess but apparently it can't utilize sql-statements (which is crucial for me).

Cheers
/Arie
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you try using the com.ms.jdbc.odbc.JdbcOdbcDriver ODBC-JDBC bridge driver?

I don't know where this driver can be downloaded or already come with OS.

Using ODBC-JDBC bridge

 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arie,

So, I don't have that driver... ok. Obviously it didn't come with my Java 7 installation.
I've heard that I can find this odbc-driver in the jar-file rt.jar but the problem is that it seems to have disappeared from there some years ago from the jre version 1.6.0.
Is it possible to download older versions of jar-files and use them in combination with new ones? Or can I extract certain java classes from old jar-files and use them i combination with the latest JRE?

The sun.jdbc.odbc.JdbcOdbcDriver is packaged in linux Java 7 too, but only as part of *Oracle's* version of the JRE.
It's not included in the OpenJDK flavour, which is the default one in Ubuntu. You can check which one you have currently installed using "java -version"; I'm guessing you have OpenJDK.

Installing Oracle JRE will solve your classnotfound problem, but unfortunately, it won't solve your overall problem of accessing Access ("accessing Access", ha!) DB.
That's because The JDBC-ODBC bridge is only one half of the chain of components required to access it.
The other missing half is the MS Access Jet engine, but that is so tightly coupled to Windows specific technologies (like Windows registry, DCOM, Win32 API, etc) that you can't reliably run it on linux (I say reliably, because some hacks like Wine may work, but I think it'll involve a lot of effort).


So what are your options?
#1 If you have a spare Windows copy, then you can install it as a guest OS on your Ubuntu host, using Virtualbox. If you're not familiar with virtualbox, then it's basically a way to run an OS inside another OS; in this case, you'd be running Windows inside Ubuntu. Then you can do all your mdb work on that Windows guest OS.

#2 Try the mdbtools ODBC driver available on linux. Install Oracle JRE (so that the sun JDBC-ODBC bridge is installed), open a console, set JAVA_HOME to point to the Oracle JRE installation instead of default OpenJDK installation, install and configure mdbtools ODBC driver, then run your app from this console so that it runs on Oracle JRE. I haven't actually tried this, so I hope this doesn't waste your time.

#3 Transfer the MDB data to a linux friendly database like MySQL / Postgresql / MariaDB, and use that, instead of Access.


I'd personally go for option #1 - especially if you use Access DBs regularly in your work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic