Ready to get started?

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

Download Now

Create a Data Access Object for Reckon Data using JDBI

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

Create a DAO for the Reckon Customers 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 MyCustomersDAO { //insert new data into Reckon @SqlUpdate("INSERT INTO Customers (Type, CustomerBalance) values (:type, :customerBalance)") void insert(@Bind("type") String type, @Bind("customerBalance") String customerBalance); //request specific data from Reckon (String type is used for simplicity) @SqlQuery("SELECT CustomerBalance FROM Customers WHERE Type = :type") String findCustomerBalanceByType(@Bind("type") String type); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Reckon

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

When you are connecting to a local Reckon instance, you do not need to set any connection properties.

Requests to Reckon are made through the Remote Connector. The Remote Connector runs on the same machine as Reckon and accepts connections through a lightweight, embedded Web server. The server supports SSL/TLS, enabling users to connect securely from remote machines.

The first time you connect to your company file, you will need to authorize the Remote Connector with Reckon. See the "Getting Started" chapter of the help documentation for a guide.

Built-in Connection String Designer

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

java -jar cdata.jdbc.reckon.jar

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

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

jdbc:reckon:User=RCUser;Password=RCUserPassword;URL=http://remotehost:8166;

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:reckon:User=RCUser;Password=RCUserPassword;URL=http://remotehost:8166;"); MyCustomersDAO dao = dbi.open(MyCustomersDAO.class); //do stuff with the DAO dao.close();

Read Reckon Data

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

//disply the result of our 'find' method String customerBalance = dao.findCustomerBalanceByType("Commercial"); System.out.println(customerBalance);

Write Reckon Data

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

//add a new entry to the Customers entity dao.insert(newType, newCustomerBalance);

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