Archived

This topic is now archived and is closed to further replies.

Darkor

[java] JDBC & MS Access

Recommended Posts

Darkor    134
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!

Share this post


Link to post
Share on other sites
Strife    374
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

Share this post


Link to post
Share on other sites
tortoise    122
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]

Share this post


Link to post
Share on other sites
tortoise    122
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.

Share this post


Link to post
Share on other sites
Darkor    134
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!

Share this post


Link to post
Share on other sites