File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem creating a Microsoft Access connection from a file

 
Alejandro Barrero
Ranch Hand
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Koen. How did yo force the use of the 32 bit driver?
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20170
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to search; that's what we have the FAQ for: http://www.coderanch.com/how-to/java/OdbcJdbcQuestions
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 335
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it and let us know!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic