2

I've run into a very annoying problem while trying to update some code. The code in question reads some (a lot actually) of info from a local MS access file (*.mdb), and then perform several operations on this data (just simple stuff). Keep in mind that I only need to read the db, nothing more.

The problem is that I'm triying to deploy this program to work in x64 operating systems (win7 mostly) and I can't access the 32-bit ODBC driver.

This is the part of the code that access the db, the variavle "path" is a string that contains the absolute path to the mdb file, as I said, this file is local.

public void openConection()
{
    try
    {
        Properties props = new Properties();
        props.put ("charSet", "ISO-8859-1");
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String dbURL = "jdbc:odbc:Driver={Microsoft AccessDriver (*.mdb)};DBQ=";
        dbURL += this.path + ";DriverID=22;READONLY=false)";
        this.connection = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft AccessDriver (*.mdb)};DBQ=" + this.path, props);
        this.statement = this.connection.createStatement();
        System.out.println("Success");
    }catch(Exception e)
    {
            System.out.println("Error :" + e);
    }
}

This throws the following error:

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The problem (as far as I can tell) is in this piece of code:

("jdbc:odbc:Driver={Microsoft AccessDriver (*.mdb)};DBQ=" + this.path, props

If I'm correct, this tries to bridge the java jdbc to MS Access ODBC, which is a 32 bit driver and therefore not accesible by the program. I tried googling my problem, but didn't find anything that could help, I did find a 64-bit MS Access driver, but it required uninstalling the 32-bit version of Office.

Also, I'd like to avoid having to create a DSN for this, as this program has to be given to a lot of people who would not know how to do that.

Thanks.

Zegpi

Zegpi
  • 63
  • 1
  • 5
  • 1
    How about http://stackoverflow.com/questions/2818491/is-there-a-64bit-driver-for-microsoft-access? – Fionnuala Sep 24 '12 at 21:13
  • Just run your program with a 32bit Java VM. That will be able to access the 32bit ODBC drivers. – a_horse_with_no_name Sep 24 '12 at 21:14
  • Remou, I can't use the drivers as they require me to uninstall the 32-bit version of office, which I can't do. a_horse_with_no_name, I coudn't find a way to make netbeans to run in 32-bit, I even reinstalled everything using the 32-bit version of JDK, but to no avail. – Zegpi Oct 02 '12 at 23:43

1 Answers1

2

You could try to read directly from the file using a Java API. There are several libraries out there.

You could try out Jackcess. It's free.

Jit B
  • 1,104
  • 10
  • 25
  • This is exactly what I was looking for, will try it as soon as I can. Thank you. I'll let you know (and accept the answer) as soon as I know it works. – Zegpi Oct 02 '12 at 23:46
  • I finally got the time to test it and it works. Thank you! – Zegpi Oct 22 '12 at 13:04