Ready to get started?

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

Download Now

Create a Data Access Object for Quandl Data using JDBI

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

Create a DAO for the Quandl AAPL 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 MyAAPLDAO { //insert new data into Quandl @SqlUpdate("INSERT INTO AAPL (Collapse, Volume) values (:collapse, :volume)") void insert(@Bind("collapse") String collapse, @Bind("volume") String volume); //request specific data from Quandl (String type is used for simplicity) @SqlQuery("SELECT Volume FROM AAPL WHERE Collapse = :collapse") String findVolumeByCollapse(@Bind("collapse") String collapse); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Quandl

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

Quandl uses an API key for authentication. See the help documentation for a guide to obtaining the APIKey property.

Additionally, set the DatabaseCode connection property to the code identifying the Database whose Datasets you want to query with SQL. You can search the available Databases by querying the Databases view.

Built-in Connection String Designer

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

java -jar cdata.jdbc.quandl.jar

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

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


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:quandl:APIKey=abc123;DatabaseCode=WIKI;"); MyAAPLDAO dao =; //do stuff with the DAO dao.close();

Read Quandl Data

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

//disply the result of our 'find' method String volume = dao.findVolumeByCollapse("Daily"); System.out.println(volume);

Write Quandl Data

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

//add a new entry to the AAPL entity dao.insert(newCollapse, newVolume);

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