Create a Data Access Object for Plaid Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Plaid JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Plaid account data including Assets, Investments, Liabilities, Transactions, and more!



A brief overview of creating a SQL Object API for Plaid 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 Plaid integrates connectivity to live Plaid data in Java applications. By pairing these technologies, you gain simple, programmatic access to Plaid data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read and write Plaid data.

Create a DAO for the Plaid Transactions 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 MyTransactionsDAO { //insert new data into Plaid @SqlUpdate("INSERT INTO Transactions (Name, Name) values (:name, :name)") void insert(@Bind("name") String name, @Bind("name") String name); //request specific data from Plaid (String type is used for simplicity) @SqlQuery("SELECT Name FROM Transactions WHERE Name = :name") String findNameByName(@Bind("name") String name); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Plaid

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

You can connect to Plaid using the embedded OAuth connectivity. When you connect, the Plaid OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.

Optionally set the Account Id property to return data related to a specific Account.

Built-in Connection String Designer

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

java -jar cdata.jdbc.plaid.jar

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

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

jdbc:plaid:AccountId=123456789;InitiateOAuth=GETANDREFRESH

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:plaid:AccountId=123456789;InitiateOAuth=GETANDREFRESH"); MyTransactionsDAO dao = dbi.open(MyTransactionsDAO.class); //do stuff with the DAO dao.close();

Read Plaid Data

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

//disply the result of our 'find' method String name = dao.findNameByName("Apple Store"); System.out.println(name);

Write Plaid Data

It is also simple to write data to Plaid, using the previously defined method.

//add a new entry to the Transactions entity dao.insert(newName, newName);

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