![]() |
VOOZH | about |
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 explains how to build a basic Data Access Object (DAO) and the accompanying code to read and write Certinia data.
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();
}
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.
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:
To obtain the security token:
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.
Set UseSandbox to true (false by default) to use a Certinia sandbox account. Ensure that you specify a sandbox user name in User.
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.
👁 Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)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();
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);
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.
Download a free trial of the Certinia Driver to get started:
Download NowLearn more:
👁 Certinia IconRapidly create and deploy powerful Java applications that integrate with Certinia.