Ready to get started?

Download a free trial of the eBay Driver to get started:

 Download Now

Learn more:

eBay Icon eBay JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with eBay auction platform data including Items, Bidders, Transactions, and more!

Create a Data Access Object for eBay Data using JDBI

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

Create a DAO for the eBay ItemListing 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 MyItemListingDAO { //insert new data into eBay @SqlUpdate("INSERT INTO ItemListing (ListingStatus, HitCount) values (:listingStatus, :hitCount)") void insert(@Bind("listingStatus") String listingStatus, @Bind("hitCount") String hitCount); //request specific data from eBay (String type is used for simplicity) @SqlQuery("SELECT HitCount FROM ItemListing WHERE ListingStatus = :listingStatus") String findHitCountByListingStatus(@Bind("listingStatus") String listingStatus); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to eBay

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

If you will be accessing your own account, you can generate an OAuthAccessToken from your developer account dashboard. You can also allow other users to securely access their own accounts.

Both of these methods require you to create an application key set to obtain values for the following connection properties: AppId, CertId, DevId, and SiteId.

The user consent flow additionally requires the RuName and CallbackURL.

See the "Getting Started" chapter in 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 eBay JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.ebay.jar

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

A connection string for eBay 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:ebay:AppId=MyAppId;CertId=MyCertId;DevId=MyDevId;SiteId=MySiteId;RuName=MyRuName;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH"); MyItemListingDAO dao =; //do stuff with the DAO dao.close();

Read eBay Data

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

//disply the result of our 'find' method String hitCount = dao.findHitCountByListingStatus("active"); System.out.println(hitCount);

Write eBay Data

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

//add a new entry to the ItemListing entity dao.insert(newListingStatus, newHitCount);

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