Ready to get started?

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

Download Now

Create a Data Access Object for Act CRM Data using JDBI

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

Create a DAO for the Act CRM Activities 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 MyActivitiesDAO { //insert new data into Act CRM @SqlUpdate("INSERT INTO Activities (Subject, Subject) values (:subject, :subject)") void insert(@Bind("subject") String subject, @Bind("subject") String subject); //request specific data from Act CRM (String type is used for simplicity) @SqlQuery("SELECT Subject FROM Activities WHERE Subject = :subject") String findSubjectBySubject(@Bind("subject") String subject); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Act CRM

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

The User and Password properties, under the Authentication section, must be set to valid Act! user credentials. In addition to the authentication values, see the following:

  • Connecting to Act! Premium

    In addition to the authentication values, the URL to Act! is also required; for example https://eup1-iis-04.eu.hosted.act.com/.

    Additionally, you must specify the ActDatabase you will connect to. This is found by going to the About Act! Premium menu of your account, at the top right of the page, in the ? menu. Use the Database Name in the window that appears.

  • Connecting to Act! Premium Cloud

    To connect to your Act! Premium Cloud account, you also need to specify the ActCloudName property. This property is found in the URL address of the Cloud account; for example https://eup1-iis-04.eu.hosted.act.com/ActCloudName/.

Note that retrieving ActCRM metadata can be expensive. It is advised that you set the CacheMetadata property to store the metadata locally.

Built-in Connection String Designer

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

java -jar cdata.jdbc.actcrm.jar

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

A connection string for Act CRM will typically look like the following:

jdbc:actcrm:URL=https://myActCRMserver.com;User=myUser;Password=myPassword;ActDatabase=MyDB;

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:actcrm:URL=https://myActCRMserver.com;User=myUser;Password=myPassword;ActDatabase=MyDB;"); MyActivitiesDAO dao = dbi.open(MyActivitiesDAO.class); //do stuff with the DAO dao.close();

Read Act CRM Data

With the connection open to Act CRM, simply call the previously defined method to retrieve data from the Activities entity in Act CRM.

//disply the result of our 'find' method String subject = dao.findSubjectBySubject("Sample subject"); System.out.println(subject);

Write Act CRM Data

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

//add a new entry to the Activities entity dao.insert(newSubject, newSubject);

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