I am using this tutorial to create a database connection from a java application to a Microsoft Access 2010 database. The tutorial creates a system dsn in windows, and then connects to that system dsn using the following line of java code:
Connection conn = DriverManager.getConnection("jdbc:odbc:DSN_NAME");
The problem is that, when I click the link to add a new system dsn at:
Control Panel --> System and Security --> Administrative Tools --> Data Sources (ODBC) --> (System DSN Tab) --> (Add.. button)
It does not give me an option to choose Microsoft Access as the database type. Instead, the options given are shown in the following printscreen:
I am wondering if this is a driver issue, where I need to download something. Or if it is a configuration issue. I am using Windows 7. Can anyone show me how to fix this so that I can create the System dsn required to complete this tutorial? Or at least show me another easy way to connect to a Microsoft Access database from java?
Advertisement
Answer
64-bit Windows machines have two separate “ODBC Data Source Administrator” control panels: one that creates 64-bit DSNs for 64-bit applications, and a separate one that creates 32-bit DSNs for 32-bit applications. On a 64-bit Windows machine,
Control Panel > Administrative Tools > Data Sources (ODBC)
will open the 64-bit ODBC Data Source Administrator. To open the 32-bit counterpart you need to run
C:WindowsSysWOW64odbcad32.exe
You don’t see an Access database driver because you are running a 64-bit version of Windows and there is no 64-bit Access driver included with Windows. Windows does ship with a 32-bit Jet driver (.mdb files only).
So, you will need to do one of the following:
If you are running a 32-bit version of Java and you want to connect to an
.mdb
file then you need to launch the 32-bit ODBC Data Source Administrator as described above.If you are running a 32-bit version of Java and you want to be able to connect to both
.accdb
and.mdb
files then you need to download and install the 32-bit version of the Access Database Engine from here and then launch the 32-bit ODBC Data Source Administrator as described above.If you are running a 64-bit version of Java then you need to download and install the 64-bit version of the Access Database Engine from here.