Ready to get started?

Download a free trial of the Azure Active Directory Driver to get started:

 Download Now

Learn more:

Azure Active Directory Icon Azure Active Directory JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Azure Active Directory.

Create a Data Access Object for Azure Active Directory Data using JDBI

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

Create a DAO for the Azure Active Directory Domains 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 MyDomainsDAO { //insert new data into Azure Active Directory @SqlUpdate("INSERT INTO Domains (isVerified, availabilityStatus) values (:isVerified, :availabilityStatus)") void insert(@Bind("isVerified") String isVerified, @Bind("availabilityStatus") String availabilityStatus); //request specific data from Azure Active Directory (String type is used for simplicity) @SqlQuery("SELECT availabilityStatus FROM Domains WHERE isVerified = :isVerified") String findavailabilityStatusByisVerified(@Bind("isVerified") String isVerified); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Azure Active Directory

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Azure Active Directory.

Azure Active Directory uses the OAuth authentication standard. To authenticate using OAuth, you will need to create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the OAuth section in the Help documentation for an authentication guide.

Built-in Connection String Designer

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

java -jar cdata.jdbc.azuread.jar

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

A connection string for Azure Active Directory 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:azuread:OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH"); MyDomainsDAO dao =; //do stuff with the DAO dao.close();

Read Azure Active Directory Data

With the connection open to Azure Active Directory, simply call the previously defined method to retrieve data from the Domains entity in Azure Active Directory.

//disply the result of our 'find' method String availabilityStatus = dao.findavailabilityStatusByisVerified("TRUE"); System.out.println(availabilityStatus);

Write Azure Active Directory Data

It is also simple to write data to Azure Active Directory, using the previously defined method.

//add a new entry to the Domains entity dao.insert(newisVerified, newavailabilityStatus);

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