Connect to Kintone Data in JRuby



Create a simple JRuby app with access to live Kintone data.

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

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

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

In addition to the authentication values, set the following parameters to connect to and retrieve data from Kintone:

  • Url: The URL of your account.
  • GuestSpaceId: Optional. Set this when using a guest space.

Authenticating with Kintone

Kintone supports the following authentication methods.

Using Password Authentication

You must set the following to authenticate:

  • User: The username of your account.
  • Password: The password of your account.

Using Basic Authentication

If the basic authentication security feature is set on the domain, supply the additional login credentials with BasicAuthUser and BasicAuthPassword. Basic authentication requires these credentials in addition to User and Password.

Using Client SSL

Instead of basic authentication, you can specify a client certificate to authenticate. Set SSLClientCert, SSLClientCertType, SSLClientCertSubject, and SSLClientCertPassword. Additionally, set User and Password to your login credentials.

Built-in Connection String Designer

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

java -jar cdata.jdbc.kintone.jar

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

Below is a typical JDBC connection string for Kintone:

jdbc:kintone:User=myuseraccount;Password=mypassword;Url=http://subdomain.domain.com;GuestSpaceId=myspaceid

Create a JRuby App with Connectivity to Kintone Data

Create a new Ruby file (for example: KintoneSelect.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 Kintone 2018/lib/cdata.jdbc.kintone.jar' url = "jdbc:kintone:User=myuseraccount;Password=mypassword;Url=http://subdomain.domain.com;GuestSpaceId=myspaceid" conn = java.sql.DriverManager.getConnection(url) stmt = conn.createStatement rs = stmt.executeQuery("SELECT CreatorName, Text FROM Comments") while (rs.next) do puts rs.getString(1) + ' ' + rs.getString(2) end

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

jruby -S KintoneSelect.rb

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

Ready to get started?

Download a free trial of the Kintone Driver to get started:

 Download Now

Learn more:

Kintone  Icon Kintone JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Kintone applications and databases.