Ready to get started?

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

 Download Now

Learn more:

Certinia Icon Certinia JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Certinia.

Create a Data Access Object for Certinia Data using JDBI



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

Create a DAO for the Certinia Account 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 MyAccountDAO { //insert new data into Certinia @SqlUpdate("INSERT INTO Account (Industry, Name) values (:industry, :name)") void insert(@Bind("industry") String industry, @Bind("name") String name); //request specific data from Certinia (String type is used for simplicity) @SqlQuery("SELECT Name FROM Account WHERE Industry = :industry") String findNameByIndustry(@Bind("industry") String industry); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Certinia

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

There are several authentication methods available for connecting to Certinia: login credentials, SSO, and OAuth.

Authenticating with a Login and Token

Set the User and Password to your login credentials. Additionally, set the SecurityToken. By default, the SecurityToken is required, but you can make it optional by allowing a range of trusted IP addresses.

To disable the security token:

  1. Log in to Certinia and enter "Network Access" in the Quick Find box in the setup section.
  2. Add your IP address to the list of trusted IP addresses.

To obtain the security token:

  1. Open the personal information page on certinia.com.
  2. Click the link to reset your security token. The token will be emailed to you.
  3. Specify the security token in the SecurityToken connection property or append it to the Password.

Authenticating with OAuth

If you do not have access to the user name and password or do not want to require them, use the OAuth user consent flow. See the OAuth section in the Help for an authentication guide.

Connecting to Certinia Sandbox Accounts

Set UseSandbox to true (false by default) to use a Certinia sandbox account. Ensure that you specify a sandbox user name in User.

Built-in Connection String Designer

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

java -jar cdata.jdbc.certinia.jar

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

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

jdbc:certinia:User=myUser;Password=myPassword;Security Token=myToken;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:certinia:User=myUser;Password=myPassword;Security Token=myToken;InitiateOAuth=GETANDREFRESH"); MyAccountDAO dao = dbi.open(MyAccountDAO.class); //do stuff with the DAO dao.close();

Read Certinia Data

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

//disply the result of our 'find' method String name = dao.findNameByIndustry("Floppy Disks"); System.out.println(name);

Write Certinia Data

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

//add a new entry to the Account entity dao.insert(newIndustry, newName);

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