wood burning stoves 2.0*
The moose likes JDBC and the fly likes Problem creating a Microsoft Access connection from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem creating a Microsoft Access connection from a file" Watch "Problem creating a Microsoft Access connection from a file" New topic
Author

Problem creating a Microsoft Access connection from a file

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 311
I have been creating a connection to a Microsoft Access database with '"jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=" + filepath' for years. It is very convenient because the users of the program don't have to create a DSN and I am using a Microsoft Access database because I just distribute a single file. My code is:

The code stopped working when I started to use 64 bit Java. I am getting the exception message "[ODBC Driver Manager] Data source name not found and no default driver specified". After searching in the internet I found that there are 32 and 64 bit drivers; Windows keeps 32 bit drivers in Windows 32 in SysWOW64. The problem is I want to distribute this program and it is not known if the users will be using a 32 bit or a 64 bit machine. I would need to specify in Java which driver to use or ask the customers to run some script to force the use of a specific driver; I haven't been able to find out how to do this.

Your help will be greatly appreciated,
Alejandro Barrero
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

I had a similar issue where my 32-bit Java code would connect to an MsAccess DB, but then stopped working after I moved to a 64-bit Java environment. I'm not sure if there really is a 64-bit MsAccess driver; at least at the time I couldn't find one so my solution was to stick to a 32-bit JRE for my application.

Edit: not sure if you can do anything with the -d32 argument to the "java" command... I haven't tested it before...
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 311
Thank you very much Koen. How did yo force the use of the 32 bit driver?
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Well the fact that there simply was no 64-bit driver in my case... there was nothing else to do except for making sure that my Java app was launched from a 32-bit JRE.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

There's a different connection string for the 64-bit case, I think; I haven't gone out and done the web search to find what it is but hopefully that isn't too hard. As for having to prompt the user, that isn't necessarily a requirement. Try connecting with the 32-bit string, and if that fails then try connecting with the 64-bit string.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41626
    
  55
No need to search; that's what we have the FAQ for: http://www.coderanch.com/how-to/java/OdbcJdbcQuestions


Ping & DNS - my free Android networking tools app
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 311
Excellent information Ulf; I will look at FAQ before I post. However, I am still having the same problem with "String url = "jdbcdbcriver={Microsoft} Access Driver (*.mdb, *.accdb);DBQ=C:/mydata/test1.mdb".

On the other hand, a big question is if there is a way of using the same code, after compilation, in 32 bit and 64 bit machines. I don't think that the problem is reduced only to creating connections with "jdbcdbcriver={Microsoft} Access Driver (*.mdb, *.accdb);DBQ=" and should also happen using DNS.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 311
Well, I used 32 bit Java in MyEclipse and it is working fine. The question is whether the compiled code will work on a 64 bit machine with 64 bit Java.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Try it and let us know!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem creating a Microsoft Access connection from a file