Create a Data Access Object for Azure Analysis Services Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Azure Analysis Services JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Azure Analysis Services.



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

Create a DAO for the Azure Analysis Services Customer 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 MyCustomerDAO { //request specific data from Azure Analysis Services (String type is used for simplicity) @SqlQuery("SELECT Education FROM Customer WHERE Country = :country") String findEducationByCountry(@Bind("country") String country); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Azure Analysis Services

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Azure Analysis Services.

To connect to Azure Analysis Services, set the Url property to a valid server, for instance, asazure://southcentralus.asazure.windows.net/server, in addition to authenticating. Optionally, set Database to distinguish which Azure database on the server to connect to.

Azure Analysis Services uses the OAuth authentication standard. OAuth requires the authenticating user to interact with Azure Analysis Services using the browser. You can connect without setting any connection properties for your user credentials. See the Help documentation for more information.

Built-in Connection String Designer

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

java -jar cdata.jdbc.aas.jar

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

A connection string for Azure Analysis Services will typically look like the following:

jdbc:aas:URL=asazure://REGION.asazure.windows.net/server;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:aas:URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH"); MyCustomerDAO dao = dbi.open(MyCustomerDAO.class); //do stuff with the DAO dao.close();

Read Azure Analysis Services Data

With the connection open to Azure Analysis Services, simply call the previously defined method to retrieve data from the Customer entity in Azure Analysis Services.

//disply the result of our 'find' method String education = dao.findEducationByCountry("Australia"); System.out.println(education);

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