Sunday, October 21, 2007

MS Access and JDBC

This describes how I set up JDBC to interact with a Microsoft Access .mdb database. The MS Access Database was installed on a Windows XP machine. The database was being accessed using JDBC on a remote Trusted Solaris machine running Java 1.2. The following instructions should apply to more configurations than just that though.

- Create the Microsoft Access Database -

1. Go into Control Panel -> Administrative Tools -> Data Sources (ODBC)
2. Click on the System DSN tab
3. Click the Add Button, choose Microsoft Access (*.mdb)
4. Choose the database name. Click the "create" button and decide on the location.
5. Click the Advanced button to give the database a username and password.
6. You can edit these options using the Configure button.


- JDBC Access for Microsoft Access -

You can use JDBC to access the MS Access database using Sun's built in ODBC driver. The Driver and the Url are as follows:

Driver: sun.jdbc.odbc.JdbcOdbcDriver
Url: jdbc:obbc:[database_name]

However, I needed to access the database from a remote host. I couldn't find any direct way to do this, due to the nature of the MS Access database. So to use access the database remotely, I used RmiJdbc. You can download it at http://rmijdbc.objectweb.org/.

RmiJdbc is a bridge to allow remote access to JDBC drivers. You'll find the RmiJdbc jar in the package, which you'll need to include on your classpath. Then you can use the following Driver and Url (to connect to the mdb Access database):

Driver: org.objectweb.rmijdbc.Driver
Url: jdbc:rmi://[host]/jdbc:obbc:[database_name]

In order for this to work, RmiJdbc needs to be listening for requests. Start up the server by executing "org.objectweb.rmijdbc.RJJdbcServer" on the machine the MS Access database is located on. Remember that to put the RmiJdbc jar on your classpath.

I'm assuming that you know how to use JDBC, so I'm going to end my instructions here.


[Reference]
http://rmijdbc.objectweb.org/
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&lngWId=2

1 comment:

Nikolai said...

Wow thanks for this post! It is really helpful.. best regards, nikolai