![]() |
VOOZH | about |
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 Zendesk integrates connectivity to live Zendesk data in Java applications. By pairing these technologies, you gain simple, programmatic access to Zendesk data. This article explains how to build a basic Data Access Object (DAO) and the accompanying code to read and write Zendesk data.
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 MyTicketsDAO {
//insert new data into Zendesk
@SqlUpdate("INSERT INTO Tickets (Industry, Subject) values (:industry, :subject)")
void insert(@Bind("industry") String industry, @Bind("subject") String subject);
//request specific data from Zendesk (String type is used for simplicity)
@SqlQuery("SELECT Subject FROM Tickets WHERE Industry = :industry")
String findSubjectByIndustry(@Bind("industry") String industry);
/*
* close with no args is used to close the connection
*/
void close();
}
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Zendesk.
To connect, set the URL and provide authentication. The URL is your Zendesk Support URL: https://{subdomain}.zendesk.com.
You can authenticate using the Basic or OAuth methods.
To use Basic authentication, specify your email address and password or your email address and an API token. Set User to your email address and follow the steps below to provide the Password or ApiToken.
See the Getting Started guide in the CData driver documentation for an authentication guide.
For assistance in constructing the JDBC URL, use the connection string designer built into the Zendesk JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.zendesk.jar
Fill in the connection properties and copy the connection string to the clipboard.
👁 Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)A connection string for Zendesk will typically look like the following:
jdbc:zendesk:URL=https://subdomain.zendesk.com;[email protected];Password=test123;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:zendesk:URL=https://subdomain.zendesk.com;[email protected];Password=test123;InitiateOAuth=GETANDREFRESH;");
MyTicketsDAO dao = dbi.open(MyTicketsDAO.class);
//do stuff with the DAO
dao.close();
With the connection open to Zendesk, simply call the previously defined method to retrieve data from the Tickets entity in Zendesk.
//disply the result of our 'find' method
String subject = dao.findSubjectByIndustry("Floppy Disks");
System.out.println(subject);
It is also simple to write data to Zendesk, using the previously defined method.
//add a new entry to the Tickets entity dao.insert(newIndustry, newSubject);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Zendesk by integrating with the CData JDBC Driver for Zendesk. Download a free trial and work with live Zendesk data in custom Java applications today.
Download a free trial of the Zendesk Driver to get started:
Download NowLearn more:
👁 Zendesk IconRapidly create and deploy powerful Java applications that integrate with Zendesk including Tickets, Groups, Users, Schedules, and more!