Java Programming/Database Programming

From Wikibooks, open books for an open world
< Java Programming
Jump to: navigation, search
Navigate Advanced topic: v  d  e )

Connecting to MS Access databases[edit]

The following is used to open an ODBC connection to an Access database. Note that the username (and password, if applicable) are given in the dsn rather than the getConnection call. This is a MS Windows-only example, due to the requirement for the Microsoft Access Driver.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String path = "C:/example.mdb";
String dsn = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + path + ";UID=admin";
accessConn = DriverManager.getConnection(dsn, "", "");