Ready to get started?

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

Download Now

Create a Data Access Object for Trello Data using JDBI

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

Create a DAO for the Trello Boards 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 MyBoardsDAO { //request specific data from Trello (String type is used for simplicity) @SqlQuery("SELECT Name FROM Boards 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 Trello

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

Trello uses token-based authentication to grant third-party applications access to their API. When a user has granted an application access to their data, the application is given a token that can be used to make requests to Trello's API.

Trello's API can be accessed in 2 different ways. The first is using Trello's own Authorization Route, and the second is using OAuth1.0.

  • Authorization Route: At the moment of registration, Trello assigns an API key and Token to the account. See the Help documentation for information on how to connect via the Authorization route.
  • OAuth Route: Similar to using Authorization, OAuth creates an Application Id and Secret when you create your account. See the Help documentation for information on how to to connect.

Built-in Connection String Designer

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

java -jar cdata.jdbc.trello.jar

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

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

jdbc:trello:APIKey=myApiKey;Token=myGeneratedToken;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:trello:APIKey=myApiKey;Token=myGeneratedToken;InitiateOAuth=GETANDREFRESH"); MyBoardsDAO dao = dbi.open(MyBoardsDAO.class); //do stuff with the DAO dao.close();

Read Trello Data

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

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

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