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 →Connect to Azure Analysis Services Data in JRuby
Create a simple JRuby app with access to live Azure Analysis Services data.
JRuby is a high-performance, stable, fully threaded Java implementation of the Ruby programming language. The CData JDBC Driver for Azure Analysis Services makes it easy to integrate connectivity to live Azure Analysis Services data in JRuby. This article shows how to create a simple JRuby app that connects to Azure Analysis Services data, executes a query, and displays the results.
Configure a JDBC Connection to Azure Analysis Services Data
Before creating the app, note the installation location for the JAR file for the JDBC Driver (typically C:\Program Files\CData\CData JDBC Driver for Azure Analysis Services\lib).
JRuby natively supports JDBC, so you can easily connect to Azure Analysis Services and execute SQL queries. Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class.
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.
Below is a typical JDBC connection string for Azure Analysis Services:
jdbc:aas:URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH
Create a JRuby App with Connectivity to Azure Analysis Services Data
Create a new Ruby file (for example: AASSelect.rb) and open it in a text editor. Copy the following code into your file:
require 'java'
require 'rubygems'
require 'C:/Program Files/CData/CData JDBC Driver for Azure Analysis Services 2018/lib/cdata.jdbc.aas.jar'
url = "jdbc:aas:URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH"
conn = java.sql.DriverManager.getConnection(url)
stmt = conn.createStatement
rs = stmt.executeQuery("SELECT Country, Education FROM Customer")
while (rs.next) do
puts rs.getString(1) + ' ' + rs.getString(2)
end
With the file completed, you are ready to display your Azure Analysis Services data with JRuby. To do so, simply run your file from the command line:
jruby -S AASSelect.rb
Writing SQL-92 queries to Azure Analysis Services allows you to quickly and easily incorporate Azure Analysis Services data into your own JRuby applications. Download a free trial today!