connection to Access 2007

For the "jdbc:odbc:<driver> ...what is the correct specification for <driver>when trying to connect to a MS Access 2007 database?WORKING example, please! the more detail, the better ... thanks!
[233 byte] By [javaStudenta] at [2007-11-26 20:20:28]
# 1

well driver here refers to DSN(Data Source Name) which you have created using your ODBC DATA SOURCE Utility....

However,take a look at the info below which gives you detalied info about of how to connect to MS Access DB(Independent of Version)...

JDBC REF:http://java.sun.com/docs/books/tutorial/jdbc/index.html

STEP BY STEP EXPLANATION OF HOW TO DO IT:http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&lngWId=2

JDBC E-book:http://www.oreilly.com/catalog/javadata/chapter/ch04.html

Step By Step(Graphical Representation):http://www.easysoft.com/applications/microsoft-access/jdbc-odbc.html

Other minor links

http://www.thescripts.com/forum/thread18812.html

http://forum.java.sun.com/thread.jspa?threadID=5132579&messageID=9478768#9478768

Hope this might help... :)

REGARDS,

RaHuL

RahulSharnaa at 2007-7-10 0:44:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Sorry, no stars for that reply.

Lots of general information, but here is the crux of the problem:

Your reference from planet-source-code.com gives this

code:

try {

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

// set this to a MS Access DB you have on your machine

String filename = "d:/java/mdbTEST.mdb";

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";

database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end

// now we can get the connection from the DriverManager

Connection con = DriverManager.getConnection( database ,"","");

}

Well, that may work with previous versions of Access, but my

question is about Access 2007. Access 2007 does NOT

produce a .mdb file, but rather a .accdb file. So, this code

will obviously fail (and it does!).

Maybe I should give one star, because you pointed to lots of

semi-useful general information, but it does NOT answer the

question!

javaStudenta at 2007-7-10 0:44:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Kind of hard to believe I am a pioneer with this ...True, Access 2007 only came out on Jan 30, 2007,but it was out there in Beta for almost a year previous.Hasn't anyone out there connected to Access 2007via JDBC?
javaStudenta at 2007-7-10 0:44:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Does it work if you configure the DSN using the ODBC tool from the control panel, then just use the DSN name? I would expect that to work.

Then if it does, get the actual name of the ODBC driver from the ODBC tool. Find the string "Microsoft Access Driver (*.mdb)" in all those examples you were linked to and replace that by the actual name of the driver. I would expect it to look similar to that, but of course be somewhat different.

And I don't know about those other parameters like DBQ and so on. The new driver might have different parameters. Of course that would be in Microsoft documentation somewhere.

You may well be a pioneer. Post answers here if you find them.

DrClapa at 2007-7-10 0:44:59 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

You are correct. My problem was not selecting the

right driver. There are now two for Access, the

older is for .mdb files only, the newer is for both

.mdb and .accdb files.

All you have to do is, in the Windows ODBC Data Source Administrator,

under User DSN, choose the Driver that works for BOTH .mdb AND .accdb

files, then point the driver to the .accdb file you have created in Access 2007.

For example, if you give the data source a name like

MyData_accdb, then the code for the connection becomes

DriverManager.getConnection("jdbc.odbc.MyData_accdb", "", "");

(last 2 parameters are userid and password, if you need them).

So, it is as easy as you say. Thank you.

Message was edited by:

javaStudent

javaStudenta at 2007-7-10 0:44:59 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> String database = "jdbc:odbc:Driver={Microsoft Access Driver ...

The problem is in confusing the java driver with the parameters that are provided to the driver.

In the above EVERYTHING after 'odbc:' is data that is provided to the odbc bridge driver (and to the ODBC shell).

And if you need to determine what that information is then often you must figure it out yourself. An excellent way to start doing that is to create a FILE DSN via the odbc applet and then look at the information in that file.

jschella at 2007-7-10 0:44:59 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
Or you could try http://www.connectionstrings.com/ - great reference! :o)
ArtisLa at 2007-7-10 0:44:59 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...