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.

Create a Data Access Object for Kintone Data using JDBI



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

Create a DAO for the Kintone Comments 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 MyCommentsDAO { //insert new data into Kintone @SqlUpdate("INSERT INTO Comments (AppId, Text) values (:appId, :text)") void insert(@Bind("appId") String appId, @Bind("text") String text); //request specific data from Kintone (String type is used for simplicity) @SqlQuery("SELECT Text FROM Comments WHERE AppId = :appId") String findTextByAppId(@Bind("appId") String appId); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Kintone

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Kintone.

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.

A connection string for Kintone will typically look like the following:

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

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:kintone:User=myuseraccount;Password=mypassword;Url=http://subdomain.domain.com;GuestSpaceId=myspaceid"); MyCommentsDAO dao = dbi.open(MyCommentsDAO.class); //do stuff with the DAO dao.close();

Read Kintone Data

With the connection open to Kintone, simply call the previously defined method to retrieve data from the Comments entity in Kintone.

//disply the result of our 'find' method String text = dao.findTextByAppId("1354841"); System.out.println(text);

Write Kintone Data

It is also simple to write data to Kintone, using the previously defined method.

//add a new entry to the Comments entity dao.insert(newAppId, newText);

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