Ready to get started?

Learn more about the CData JDBC Driver for OFX or download a free trial:

Download Now

Create a Data Access Object for OFX Data using JDBI

A brief overview of creating a SQL Object API for OFX data in JDBI.

JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for OFX integrates connectivity to live OFX data in Java applications. By pairing these technologies, you gain simple, programmatic access to OFX data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read OFX data.

Create a DAO for the OFX InvBalances Entity

The interface below declares the desired behavior for the SQL object to create a single method for each SQL statement to be implemented.

public interface MyInvBalancesDAO { //request specific data from OFX (String type is used for simplicity) @SqlQuery("SELECT Amount FROM InvBalances WHERE ServiceType = :serviceType") String findAmountByServiceType(@Bind("serviceType") String serviceType); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to OFX

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to OFX.

The OFXUser and OFXPassword properties, under the Authentication section, must be set to valid OFX user credentials. In addition to this, you will need to configure FIURL, FIOrganizationName, and FIID, which will be specific for the financial institution. You will also need to provide application-specific settings, including OFXVersion, ApplicationVersion, and ApplicationId.

To connect to some services, you will need to provide additional account information such as AccountId, AccountType, BankId, BrokerId, and CCNumber.

Built-in Connection String Designer

For assistance in constructing the JDBC URL, use the connection string designer built into the OFX JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.ofx.jar

Fill in the connection properties and copy the connection string to the clipboard.

A connection string for OFX will typically look like the following:

jdbc:ofx:OFXUser=myUser;OFXPassword=myPassword;FIID=myFIID;

Use the configured JDBC URL to obtain an instance of the DAO interface. The particular method shown below will open a handle bound to the instance, so the instance needs to be closed explicitly to release the handle and the bound JDBC connection.

DBI dbi = new DBI("jdbc:ofx:OFXUser=myUser;OFXPassword=myPassword;FIID=myFIID;"); MyInvBalancesDAO dao = dbi.open(MyInvBalancesDAO.class); //do stuff with the DAO dao.close();

Read OFX Data

With the connection open to OFX, simply call the previously defined method to retrieve data from the InvBalances entity in OFX.

//disply the result of our 'find' method String amount = dao.findAmountByServiceType("CREDITCARD"); System.out.println(amount);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for OFX by integrating with the CData JDBC Driver for OFX. Download a free trial and work with live OFX data in custom Java applications today.