Connect to Google Data Catalog Data in JRuby

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Google Data Catalog JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Google Data Catalog.



Create a simple JRuby app with access to live Google Data Catalog data.

JRuby is a high-performance, stable, fully threaded Java implementation of the Ruby programming language. The CData JDBC Driver for Google Data Catalog makes it easy to integrate connectivity to live Google Data Catalog data in JRuby. This article shows how to create a simple JRuby app that connects to Google Data Catalog data, executes a query, and displays the results.

Configure a JDBC Connection to Google Data Catalog 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 Google Data Catalog\lib).

JRuby natively supports JDBC, so you can easily connect to Google Data Catalog and execute SQL queries. Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class.

Google Data Catalog uses the OAuth authentication standard. Authorize access to Google APIs on behalf on individual users or on behalf of users in a domain.

Before connecting, specify the following to identify the organization and project you would like to connect to:

  • OrganizationId: The ID associated with the Google Cloud Platform organization resource you would like to connect to. Find this by navigating to the cloud console.

    Click the project selection drop-down, and select your organization from the list. Then, click More -> Settings. The organization ID is displayed on this page.

  • ProjectId: The ID associated with the Google Cloud Platform project resource you would like to connect to.

    Find this by navigating to the cloud console dashboard and selecting your project from the Select from drop-down. The project ID will be present in the Project info card.

When you connect, the OAuth endpoint opens in your default browser. Log in and grant permissions to the application to completes the OAuth process. For more information, refer to the OAuth section in the Help documentation.

Built-in Connection String Designer

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

java -jar cdata.jdbc.googledatacatalog.jar

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

Below is a typical JDBC connection string for Google Data Catalog:

jdbc:googledatacatalog:ProjectId=YourProjectId;InitiateOAuth=GETANDREFRESH

Create a JRuby App with Connectivity to Google Data Catalog Data

Create a new Ruby file (for example: GoogleDataCatalogSelect.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 Google Data Catalog 2018/lib/cdata.jdbc.googledatacatalog.jar' url = "jdbc:googledatacatalog:ProjectId=YourProjectId;InitiateOAuth=GETANDREFRESH" conn = java.sql.DriverManager.getConnection(url) stmt = conn.createStatement rs = stmt.executeQuery("SELECT Type, DatasetName FROM Schemas") while (rs.next) do puts rs.getString(1) + ' ' + rs.getString(2) end

With the file completed, you are ready to display your Google Data Catalog data with JRuby. To do so, simply run your file from the command line:

jruby -S GoogleDataCatalogSelect.rb

Writing SQL-92 queries to Google Data Catalog allows you to quickly and easily incorporate Google Data Catalog data into your own JRuby applications. Download a free trial today!