Ready to get started?

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

Download Now

Create a Data Access Object for FedEx Data using JDBI

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

Create a DAO for the FedEx Senders 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 MySendersDAO { //insert new data into FedEx @SqlUpdate("INSERT INTO Senders (SenderID, Phone) values (:senderID, :phone)") void insert(@Bind("senderID") String senderID, @Bind("phone") String phone); //request specific data from FedEx (String type is used for simplicity) @SqlQuery("SELECT Phone FROM Senders WHERE SenderID = :senderID") String findPhoneBySenderID(@Bind("senderID") String senderID); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to FedEx

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

There are five pieces of information needed in order to authenticate its actions with the FedEx service. This information is below.

  • Server: This controls the URL where the requests should be sent. Common testing options for this are: "", "", "", and ""
  • DeveloperKey: This is the identifier part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • Password: This is the secret part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • AccountNumber: This valid 9-digit FedEx account number is used for logging into the FedEx server.
  • MeterNumber: This value is used for submitting requests to FedEx. This value will be provided to you by FedEx after registration.
  • PrintLabelLocation: This property is required if one intends to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

The Cache Database

Many of the useful tasks available from FedEx require a lot of data. To ensure this data is easy to input and recall later, utilizes a cache database to make these requests. You must set the cache connection properties:

  • CacheProvider: The specific database you are using to cache with. For example, org.sqlite.JDBC.
  • CacheConnection: The connection string to be passed to the cache provider. For example, jdbc:sqlite:C:\users\username\documents\fedexcache.db

Built-in Connection String Designer

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

java -jar

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

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

jdbc:fedex:Server='';DeveloperKey='alsdkfjpqoewiru';Password='zxczxqqtyiuowkdlkn';AccountNumber='110371337';MeterNumber='240134349'; PrintLabelLocation='C:\users\username\documents\mylabels';CacheProvider='org.sqlite.JDBC';CacheConnection='jdbc:sqlite:C:\users\username\documents\fedexcache.db';

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:fedex:Server='';DeveloperKey='alsdkfjpqoewiru';Password='zxczxqqtyiuowkdlkn';AccountNumber='110371337';MeterNumber='240134349'; PrintLabelLocation='C:\users\username\documents\mylabels';CacheProvider='org.sqlite.JDBC';CacheConnection='jdbc:sqlite:C:\users\username\documents\fedexcache.db';"); MySendersDAO dao =; //do stuff with the DAO dao.close();

Read FedEx Data

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

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

Write FedEx Data

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

//add a new entry to the Senders entity dao.insert(newSenderID, newPhone);

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