We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Create a Data Access Object for ServiceNow Data using JDBI
A brief overview of creating a SQL Object API for ServiceNow 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 ServiceNow integrates connectivity to live ServiceNow data in Java applications. By pairing these technologies, you gain simple, programmatic access to ServiceNow data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read ServiceNow data.
About ServiceNow Data Integration
CData simplifies access and integration of live ServiceNow data. Our customers leverage CData connectivity to:
- Get optimized performance since CData uses the REST API for data and the SOAP API for schema.
- Read, write, update, and delete ServiceNow objects like Schedules, Timelines, Questions, Syslogs and more.
- Use SQL stored procedures for actions like adding items to a cart, submitting orders, and downloading attachments.
- Securely authenticate with ServiceNow, including basic (username and password), OKTA, ADFS, OneLogin, and PingFederate authentication schemes.
Many users access live ServiceNow data from preferred analytics tools like Tableau, Power BI, and Excel, and use CData solutions to integrate ServiceNow data with their database or data warehouse.
Getting Started
Create a DAO for the ServiceNow incident 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 MyincidentDAO {
//request specific data from ServiceNow (String type is used for simplicity)
@SqlQuery("SELECT priority FROM incident WHERE category = :category")
String findpriorityBycategory(@Bind("category") String category);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to ServiceNow
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to ServiceNow.
ServiceNow uses the OAuth 2.0 authentication standard. To authenticate using OAuth, register an OAuth app with ServiceNow to obtain the OAuthClientId and OAuthClientSecret connection properties. In addition to the OAuth values, specify the Instance, Username, and Password connection properties.
See the "Getting Started" chapter in the help documentation for a guide on connecting to ServiceNow.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the ServiceNow JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.servicenow.jar
Fill in the connection properties and copy the connection string to the clipboard.

A connection string for ServiceNow will typically look like the following:
jdbc:servicenow:OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;Username=MyUsername;Password=MyPassword;URL=https://myinstance12345.service-now-com;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:servicenow:OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;Username=MyUsername;Password=MyPassword;URL=https://myinstance12345.service-now-com;InitiateOAuth=GETANDREFRESH");
MyincidentDAO dao = dbi.open(MyincidentDAO.class);
//do stuff with the DAO
dao.close();
Read ServiceNow Data
With the connection open to ServiceNow, simply call the previously defined method to retrieve data from the incident entity in ServiceNow.
//disply the result of our 'find' method
String priority = dao.findpriorityBycategory("request");
System.out.println(priority);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for ServiceNow by integrating with the CData JDBC Driver for ServiceNow. Download a free trial and work with live ServiceNow data in custom Java applications today.