Easysoft JDBC-Access Gateway User's Guide - Connection

Connecting to Access

Before connecting to your Access database from Java, you must have successfully installed the Easysoft JDBC-Access Gateway.

For Easysoft JDBC-Access Gateway installation instructions, see Installation.

Chapter Guide

Connecting to your Access Database

Registering the Easysoft JDBC-Access Gateway

To register the Easysoft JDBC-Access Gateway JDBC driver, your Java application must specify the class easysoft.sql.esMdbDriver. For example:

Class.forName("easysoft.sql.esMdbDriver");

The Connection URL

When the Easysoft JDBC-Access Gateway JDBC driver is registered, you can establish a connection by using a connection URL and the getConnection method of the DriverManagerclass. For example:

String connectionUrl = "jdbc:easysoft:mdb?DBQ=C:/Users/Public/Northwind.mdb";

Connection con = DriverManager.getConnection(connectionUrl);

To establish a connection with the Easysoft JDBC-Access Gateway, use a connection URL of the form:

jdbc:easysoft:mdb?DBQ=<path>[;<odbc-driver-attribute>=<value>]

where:

<path> is the path to the Access database (.mdb).

<odbc-driver-attribute> is an Access ODBC driver attribute.

You can retrieve the available Access ODBC driver attributes along with a description for each attribute by using the getPropertyInfo method of the Driver class. For example:

public static void driverProperties() {

// Replace the DBQ value with the path to your Access database.

String connectionUrl = "jdbc:easysoft:mdb?" +

"DBQ=C:/Northwind/BlankII.mdb";

Driver driver = null;

DriverPropertyInfo props[] = null;

try {

Class.forName("easysoft.sql.esMdbDriver");

driver = DriverManager.getDriver(connectionUrl);

props = driver.getPropertyInfo (connectionUrl, new Properties());

System.out.println ("JDBC URL Attributes");

for (int i = 0; i < props.length; i++) {

System.out.print ("\t" + props[i].name);

System.out.print (" = ");

System.out.print (props[i].value);

System.out.print (" : ");

System.out.println (props[i].description +".");

}

}

catch (Exception e) {

e.printStackTrace();

}

}

Example Connection URLs

Opens an Access database and enables Jet 4.0 features:

jdbc:easysoft:mdb?DBQ=C:/Users/Public/Northwind.mdb;ExtendedAnsiSQL=True

Opens an an Access database that is stored in a shared folder:

jdbc:easysoft:mdb?DBQ=//mymachine/myshare/Sales.accdb

Opens a password-protected Access database from a mapped network drive:

jdbc:easysoft:mdb?DBQ=Z:/Orgdata.mdb;PWD=p455w0rd