• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem creating a Microsoft Access connection from a file

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been creating a connection to a Microsoft Access database with '"jdbc:odbc:Driver={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.
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need to search; that's what we have the FAQ for: https://coderanch.com/how-to/java/OdbcJdbcQuestions
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 = "jdbc:odbc:Driver={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 "jdbc:odbc:Driver={Microsoft} Access Driver (*.mdb, *.accdb);DBQ=" and should also happen using DNS.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it and let us know!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic