0

How to connect to a Microsoft Access-based database in a Windows using JDBC code?

What syntax is to be written for Type-1 and Type-4 types of the drivers?

Class.forName(" ");

Is the above syntax different for everytype of the driver we use? How can we define and identify the type of the driver we use??

If possible then also specify for the oracle also the driver syntax to be loaded..

Vijay Agrawal
  • 3,365
  • 1
  • 18
  • 24
user460920
  • 837
  • 5
  • 17
  • 26
  • 1
    I tried Google, this seemed like a reasonable page, from scanning it: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&lngWId=2 – Matt Harrison Mar 25 '12 at 20:03
  • 1
    You need to use the JDBC-ODBC bridge See: http://stackoverflow.com/questions/6339055/how-to-connect-java-to-ms-access-2010 for details – Vijay Agrawal Mar 25 '12 at 20:02
  • con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ="+ f.getPath() + "//db//JavaAccess.accd","",""); In the above line for making a connection what does DBQ means and thenafter why f.getPath() + "//db//JavaAccess.accd","",""); is written. Thanks.. – user460920 Mar 26 '12 at 03:47

4 Answers4

7

I recommend a cross-platform Access JDBC driver called UCanAccess. It works great and there are lots of examples on the site (to help the original poster.)

T Hallman
  • 71
  • 1
  • 2
7

You can use JDBC-ODBC bridge by calling:

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

Then you can use JDBC database URL in form:

jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\Nwind.mdb

or if you configure your database in ODBC manager you can use its alias:

jdbc:odbc:northwind
Michał Niklas
  • 48,759
  • 16
  • 62
  • 100
  • 5
    Just a note that the JDBC-ODBC Bridge has been removed from the Java 8 JDK and is not supported (ref: [here](http://docs.oracle.com/javase/7/docs/technotes/guides/jdbc/bridge.html) and [here](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6345277)). Alternatives include [Jackcess](http://jackcess.sourceforge.net/) and [UCanAccess](http://ucanaccess.sourceforge.net/site.html). – Gord Thompson Jan 20 '14 at 20:12
  • `sun.jdbc.odbc.JdbcOdbcDriver` does not work any more with Java8 – SaidbakR Sep 26 '14 at 12:54
1

JDBC/ODBC driver is a platform dependent and can be used only in Windows OS. Also, there are some platform independent JDBC drivers, for example: StelsMDB JDBC driver (http://www.csv-jdbc.com/stels_mdb_jdbc.htm)

serg kunz
  • 317
  • 1
  • 3
  • 8
-1

To connect Java with MS Access, you need a JDBC driver. I still don't think Microsoft do one do they! http://www.easysoft.com/applications/microsoft-access/jdbc-odbc.html