Ready to get started?

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

Download Now

JDBI からBing Ads Data のデータアクセスオブジェクトを作成

JDBI でBing Ads data 用のSQL オブジェクトAPIを作成する方法を概説します。

JDBI は、Fluent スタイルとSQL オブジェクトスタイルという2つの異なるスタイルAPI を公開する、Java 用のSQL コンビニエンスライブラリです。CData JDBC Driver for Bing Ads は、Java アプリケーションとリアルタイムBing Ads data のデータ連携を実現します。これらの技術を組み合わせることによって、Bing Ads data へのシンプルなコードアクセスが可能になります。ここでは、基本的なDAO(Data Access Object )とそれに付随するBing Ads data の読み書きのためのコードの作成について説明します。

Bing Ads AdGroups Entity のDAO を作成

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 MyAdGroupsDAO { //insert new data into Bing Ads @SqlUpdate("INSERT INTO AdGroups (CampaignId, Name) values (:campaignId, :name)") void insert(@Bind("campaignId") String campaignId, @Bind("name") String name); //request specific data from Bing Ads (String type is used for simplicity) @SqlQuery("SELECT Name FROM AdGroups WHERE CampaignId = :campaignId") String findNameByCampaignId(@Bind("campaignId") String campaignId); /* * close with no args is used to close the connection */ void close(); }

Bing Ads への接続を開く

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

The Bing Ads APIs use the OAuth 2 standard. To authenticate, you will need valid Bing Ads OAuth credentials and you will need to obtain a developer token. See the Getting Started section in the Bing Ads data provider help documentation for an authentication guide.


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

java -jar cdata.jdbc.bingads.jar

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

A connection string for Bing Ads will typically look like the following:

jdbc:bingads: OAuthClientId=MyOAuthClientId; OAuthClientSecret=MyOAuthClientSecret; CallbackURL=http://localhost:portNumber; AccountId=442311; CustomerId=5521444; DeveloperToken=11112332233;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:bingads: OAuthClientId=MyOAuthClientId; OAuthClientSecret=MyOAuthClientSecret; CallbackURL=http://localhost:portNumber; AccountId=442311; CustomerId=5521444; DeveloperToken=11112332233;InitiateOAuth=GETANDREFRESH"); MyAdGroupsDAO dao =; //do stuff with the DAO dao.close();

Bing Ads Data について

With the connection open to Bing Ads, simply call the previously defined method to retrieve data from the AdGroups entity in Bing Ads.

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

Bing Ads Data の書き方

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

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

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