Create a Data Access Object for Jira Service Desk Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Jira Service Desk JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Jira Service Desk.



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

Create a DAO for the Jira Service Desk Requests 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 MyRequestsDAO { //insert new data into Jira Service Desk @SqlUpdate("INSERT INTO Requests (CurrentStatus, ReporterName) values (:currentStatus, :reporterName)") void insert(@Bind("currentStatus") String currentStatus, @Bind("reporterName") String reporterName); //request specific data from Jira Service Desk (String type is used for simplicity) @SqlQuery("SELECT ReporterName FROM Requests WHERE CurrentStatus = :currentStatus") String findReporterNameByCurrentStatus(@Bind("currentStatus") String currentStatus); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Jira Service Desk

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Jira Service Desk.

You can establish a connection to any Jira Service Desk Cloud account or Server instance.

Connecting with a Cloud Account

To connect to a Cloud account, you'll first need to retrieve an APIToken. To generate one, log in to your Atlassian account and navigate to API tokens > Create API token. The generated token will be displayed.

Supply the following to connect to data:

  • User: Set this to the username of the authenticating user.
  • APIToken: Set this to the API token found previously.

Connecting with a Service Account

To authenticate with a service account, you will need to supply the following connection properties:

  • User: Set this to the username of the authenticating user.
  • Password: Set this to the password of the authenticating user.
  • URL: Set this to the URL associated with your JIRA Service Desk endpoint. For example, https://yoursitename.atlassian.net.

Note: Password has been deprecated for connecting to a Cloud Account and is now used only to connect to a Server Instance.

Accessing Custom Fields

By default, the connector only surfaces system fields. To access the custom fields for Issues, set IncludeCustomFields.

Built-in Connection String Designer

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

java -jar cdata.jdbc.jiraservicedesk.jar

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

A connection string for Jira Service Desk will typically look like the following:

jdbc:jiraservicedesk:ApiKey=myApiKey;User=MyUser;InitiateOAuth=GETANDREFRESH

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:jiraservicedesk:ApiKey=myApiKey;User=MyUser;InitiateOAuth=GETANDREFRESH"); MyRequestsDAO dao = dbi.open(MyRequestsDAO.class); //do stuff with the DAO dao.close();

Read Jira Service Desk Data

With the connection open to Jira Service Desk, simply call the previously defined method to retrieve data from the Requests entity in Jira Service Desk.

//disply the result of our 'find' method String reporterName = dao.findReporterNameByCurrentStatus("Open"); System.out.println(reporterName);

Write Jira Service Desk Data

It is also simple to write data to Jira Service Desk, using the previously defined method.

//add a new entry to the Requests entity dao.insert(newCurrentStatus, newReporterName);

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