Ready to get started?

Download a free trial of the DoubleClick (DFP) Driver to get started:

 Download Now

Learn more:

DoubleClick For Publishers Icon DoubleClick (DFP) JDBC Driver

An easy-to-use database-like interface for Java based applications and reporting tools access to live DoubleClick For Publishers data (Companies, Contacts, Placements, Users, and more).

Create a Data Access Object for Google Ad Manager Data using JDBI

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

Create a DAO for the Google Ad Manager Orders 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 MyOrdersDAO { //insert new data into Google Ad Manager @SqlUpdate("INSERT INTO Orders (Id, Name) values (:id, :name)") void insert(@Bind("id") String id, @Bind("name") String name); //request specific data from Google Ad Manager (String type is used for simplicity) @SqlQuery("SELECT Name FROM Orders WHERE Id = :id") String findNameById(@Bind("id") String id); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Google Ad Manager

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Google Ad Manager.

Google Ads Manager uses the OAuth authentication standard. You can authorize the data provider to access Google Ads Manager as an individual user or with a service account that you create in the Google APIs Console. See the Getting Started section in the data provider help documentation for an authentication guide.

Built-in Connection String Designer

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

java -jar cdata.jdbc.googleadsmanager.jar

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

A connection string for Google Ad Manager will typically look like the following:


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:googleadsmanager:InitiateOAuth=GETANDREFRESH"); MyOrdersDAO dao =; //do stuff with the DAO dao.close();

Read Google Ad Manager Data

With the connection open to Google Ad Manager, simply call the previously defined method to retrieve data from the Orders entity in Google Ad Manager.

//disply the result of our 'find' method String name = dao.findNameById("2112976978"); System.out.println(name);

Write Google Ad Manager Data

It is also simple to write data to Google Ad Manager, using the previously defined method.

//add a new entry to the Orders entity dao.insert(newId, newName);

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