Create a Data Access Object for Oracle Eloqua Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Eloqua JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Eloqua marketing automation platform including Contacts, Campaigns, Emails, Activities, and more!



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

Create a DAO for the Oracle Eloqua Campaign 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 MyCampaignDAO { //insert new data into Oracle Eloqua @SqlUpdate("INSERT INTO Campaign (ShipCity, ActualCost) values (:shipCity, :actualCost)") void insert(@Bind("shipCity") String shipCity, @Bind("actualCost") String actualCost); //request specific data from Oracle Eloqua (String type is used for simplicity) @SqlQuery("SELECT ActualCost FROM Campaign WHERE ShipCity = :shipCity") String findActualCostByShipCity(@Bind("shipCity") String shipCity); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Oracle Eloqua

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

There are two authentication methods available for connecting to Oracle Eloqua: Login and OAuth. The Login method requires you to have the Company, User, and Password of the user.

If you do not have access to the username and password or do not wish to require them, you can use OAuth authentication. OAuth is better suited for allowing other users to access their own data. Using login credentials is better suited for accessing your own data.

Built-in Connection String Designer

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

java -jar cdata.jdbc.oracleeloqua.jar

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

A connection string for Oracle Eloqua will typically look like the following:

jdbc:oracleeloqua:User=user;Password=password;Company=CData;

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:oracleeloqua:User=user;Password=password;Company=CData;"); MyCampaignDAO dao = dbi.open(MyCampaignDAO.class); //do stuff with the DAO dao.close();

Read Oracle Eloqua Data

With the connection open to Oracle Eloqua, simply call the previously defined method to retrieve data from the Campaign entity in Oracle Eloqua.

//disply the result of our 'find' method String actualCost = dao.findActualCostByShipCity("New York"); System.out.println(actualCost);

Write Oracle Eloqua Data

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

//add a new entry to the Campaign entity dao.insert(newShipCity, newActualCost);

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