Ready to get started?

Learn more about the CData JDBC Driver for FinancialForce or download a free trial:

Download Now

Connect to FinancialForce Data in JRuby

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

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

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

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

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 FinancialForce.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 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.

Below is a typical JDBC connection string for FinancialForce:

jdbc:financialforce:User=myUser;Password=myPassword;Security Token=myToken;InitiateOAuth=GETANDREFRESH

Create a JRuby App with Connectivity to FinancialForce Data

Create a new Ruby file (for example: FinancialForceSelect.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 FinancialForce 2018/lib/cdata.jdbc.financialforce.jar' url = "jdbc:financialforce:User=myUser;Password=myPassword;Security Token=myToken;InitiateOAuth=GETANDREFRESH" conn = java.sql.DriverManager.getConnection(url) stmt = conn.createStatement rs = stmt.executeQuery("SELECT BillingState, Name FROM Account") while (rs.next) do puts rs.getString(1) + ' ' + rs.getString(2) end

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

jruby -S FinancialForceSelect.rb

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