Ready to get started?

Learn more about the CData JDBC Driver for AWS Management or download a free trial:

Download Now

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

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

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

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

AWS Management への接続を開く

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

To authorize AWSDataManagement requests, provide the credentials for an administrator account or for an IAM user with custom permissions:

  1. Set AccessKey to the access key Id.
  2. Set SecretKey to the secret access key.
  3. Set Region to the region where your AWSDataManagement data is hosted.

Note: Though you can connect as the AWS account administrator, it is recommended to use IAM user credentials to access AWS services.

ビルトイン接続文字列デザイナー

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

java -jar cdata.jdbc.awsdatamanagement.jar

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

A connection string for AWS Management will typically look like the following:

jdbc:awsdatamanagement:AccessKey=myAccessKey;Account=myAccountName;Region=us-east-1;

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:awsdatamanagement:AccessKey=myAccessKey;Account=myAccountName;Region=us-east-1;"); MyNorthwingProductsDAO dao = dbi.open(MyNorthwingProductsDAO.class); //do stuff with the DAO dao.close();

AWS Management Data について

With the connection open to AWS Management, simply call the previously defined method to retrieve data from the NorthwingProducts entity in AWS Management.

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

AWS Management Data の書き方

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

//add a new entry to the NorthwingProducts 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 AWS Management by integrating with the CData JDBC Driver for AWS Management.Download a free trial and work with live AWS Management data in custom Java applications today.

 
 
ダウンロード