[java] JDBC & MS Access

Started by
4 comments, last by Darkor 20 years, 7 months ago
Sorry for another non-game related post on Java databases! Anyway, I''ve just spent an hour wading through JDBC tutorials and search results, but have yet to come across the code to connect to a MS Access database. All they ever say is to read the driver''s documentation for more information. This is kinda frustrating. Please point me in the right direction with a tutorial or two. Thanks in advance!
Advertisement
I would assume that it says read that stuff for a reason. I don''t think too many people are going to be doing this, and so chances are no tutorials exist for it (or at least, no good, comprehensive ones). After all, MS Access is only really used on, obviously, Microsoft systems, which goes against the concept of Java in the first place.

However, that''s not to say that it''s not possible, just that it''s rather rare.

The Artist Formerly Known as CmndrM

http://chaos.webhop.org
It's very easy. Set up your Access database in the ODBC control panel (the pc I'm currently on has control panel access locked out, so I can't give you details). Amongst the settings in here will be a name required for the database, give it a descriptive name and take note of it.

In your Java app, use the JDBC to ODBC driver, it comes with the JDK.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Or the various other ways of establishing a JDBC driver.

Now connect to your database as usual

Connection con = DriverManager.getConnection("jdbc:odbc:nameOfDatabase",
"myLogin", "myPassword");

from there it's just like any other SQL database.

And as for it being rare, I'd have to disagree. It's a very easy and straightforward way of testing a new database app you're writing. At my last place of work we did it all the time. Transfering to a real database required no changing of code. Yup, JDBC rocks

[edited by - tortoise on September 3, 2003 1:50:15 PM]
Wow, I stand corrected.

I guess I really shouldn''t comment too much on DB questions since I know very little about them.

The Artist Formerly Known as CmndrM

http://chaos.webhop.org
And just to clarify, the ODBC control panel is in administrative tools on XP and probably 2K. I believe it''s in the control panel proper on Win9x. Choose add..., pick "Microsoft Access Driver" (what''s up with the Spanish drivers anyway?), and from there it''s pretty obvious.
Thanks for the replies, yeah I already have the ODBC settings set up. But I didn''t know that you use the same name of the database for the connection string. Thanks for clearing it up. =p

Well I think mostly, people don''t use MS Access for databases either. Not if the project is critical right? But I''m working on a school project. And I don''t fancy database programming very much either =x

But I would much appreciate it if someone does actually know where this driver documentation is. I''ve searched MSDN too, but I found a host of other unrelated stuff.

Anyway, I thanks again!

This topic is closed to new replies.

Advertisement