Create a Data Access Object for Evernote Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Evernote JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Evernote data including Notebooks, Notes, Searches, Tags, and more!

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

Create a DAO for the Evernote Notes 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 MyNotesDAO { //insert new data into Evernote @SqlUpdate("INSERT INTO Notes (Guid, Author) values (:guid, :author)") void insert(@Bind("guid") String guid, @Bind("author") String author); //request specific data from Evernote (String type is used for simplicity) @SqlQuery("SELECT Author FROM Notes WHERE Guid = :guid") String findAuthorByGuid(@Bind("guid") String guid); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Evernote

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

Evernote uses the OAuth authentication standard. You can use the embedded OAuth application to connect without setting any connection properties. Alternatively, you can create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the "Getting Started" chapter of the help documentation for a guide to using OAuth.

Built-in Connection String Designer

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

java -jar cdata.jdbc.evernote.jar

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

A connection string for Evernote 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:evernote:OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH"); MyNotesDAO dao =; //do stuff with the DAO dao.close();

Read Evernote Data

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

//disply the result of our 'find' method String author = dao.findAuthorByGuid("ab26f704-5edf-4a9f-9e4c-8da893a4acd8"); System.out.println(author);

Write Evernote Data

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

//add a new entry to the Notes entity dao.insert(newGuid, newAuthor);

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