Create a Data Access Object for ShipStation Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

ShipStation JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with ShipStation.



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

Create a DAO for the ShipStation Tags 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 MyTagsDAO { //request specific data from ShipStation (String type is used for simplicity) @SqlQuery("SELECT Color FROM Tags WHERE CustomerId = :customerId") String findColorByCustomerId(@Bind("customerId") String customerId); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to ShipStation

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

Use the BASIC Authentication standard to connect.

  1. Login to your ShipStation account
  2. Click on the settings icon in the upper right corner. A column menu will show up on the left
  3. Click Account -> API Settings
  4. On the API Settings page, note the API Key and API Secret.

Authenticating to ShipStation

  • APIKey: Set this to the API key from the API settings page.
  • APISecret: Set this to the Secret key from the API settings page.

Built-in Connection String Designer

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

java -jar cdata.jdbc.shipstation.jar

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

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

jdbc:shipstation:APIKey='YourAPIKey';APISecret='YourAPISecret'

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:shipstation:APIKey='YourAPIKey';APISecret='YourAPISecret'"); MyTagsDAO dao = dbi.open(MyTagsDAO.class); //do stuff with the DAO dao.close();

Read ShipStation Data

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

//disply the result of our 'find' method String color = dao.findColorByCustomerId("1368175"); System.out.println(color);

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