Create a Data Access Object for FinancialForce Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

FinancialForce JDBC Driver

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

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

Create a DAO for the FinancialForce 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 FinancialForce @SqlUpdate("INSERT INTO Account (Industry, Name) values (:industry, :name)") void insert(@Bind("industry") String industry, @Bind("name") String name); //request specific data from FinancialForce (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 FinancialForce

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

There are several authentication methods available for connecting to FinancialForce: 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 FinancialForce 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
  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 FinancialForce Sandbox Accounts

Set UseSandbox to true (false by default) to use a FinancialForce 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 FinancialForce JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.financialforce.jar

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

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

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

Read FinancialForce Data

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

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

Write FinancialForce Data

It is also simple to write data to FinancialForce, 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 FinancialForce by integrating with the CData JDBC Driver for FinancialForce. Download a free trial and work with live FinancialForce data in custom Java applications today.