Ready to get started?

Download a free trial of the ADP Driver to get started:

 Download Now

Learn more:

ADP Icon ADP JDBC Driver

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

Create a Data Access Object for ADP Data using JDBI



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

Create a DAO for the ADP Workers 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 MyWorkersDAO { //insert new data into ADP @SqlUpdate("INSERT INTO Workers (AssociateOID, WorkerID) values (:associateOID, :workerID)") void insert(@Bind("associateOID") String associateOID, @Bind("workerID") String workerID); //request specific data from ADP (String type is used for simplicity) @SqlQuery("SELECT WorkerID FROM Workers WHERE AssociateOID = :associateOID") String findWorkerIDByAssociateOID(@Bind("associateOID") String associateOID); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to ADP

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

Connect to ADP by specifying the following properties:

  • SSLClientCert: Set this to the certificate provided during registration.
  • SSLClientCertPassword: Set this to the password of the certificate.
  • UseUAT: The connector makes requests to the production environment by default. If using a developer account, set UseUAT = true.
  • RowScanDepth: The maximum number of rows to scan for the custom fields columns available in the table. The default value will be set to 100. Setting a high value may decrease performance.

The connector uses OAuth to authenticate with ADP. OAuth requires the authenticating user to interact with ADP using the browser. For more information, refer to the OAuth section in the Help documentation.

Built-in Connection String Designer

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

java -jar cdata.jdbc.adp.jar

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

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

jdbc:adp:OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;SSLClientCert='c:\cert.pfx';SSLClientCertPassword='admin@123'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:adp:OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;SSLClientCert='c:\cert.pfx';SSLClientCertPassword='admin@123'InitiateOAuth=GETANDREFRESH"); MyWorkersDAO dao = dbi.open(MyWorkersDAO.class); //do stuff with the DAO dao.close();

Read ADP Data

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

//disply the result of our 'find' method String workerID = dao.findWorkerIDByAssociateOID("G3349PZGBADQY8H8"); System.out.println(workerID);

Write ADP Data

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

//add a new entry to the Workers entity dao.insert(newAssociateOID, newWorkerID);

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