Ready to get started?

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

Download Now

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

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

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

FedEx Senders 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 MySendersDAO { //insert new data into FedEx @SqlUpdate("INSERT INTO Senders (SenderID, Phone) values (:senderID, :phone)") void insert(@Bind("senderID") String senderID, @Bind("phone") String phone); //request specific data from FedEx (String type is used for simplicity) @SqlQuery("SELECT Phone FROM Senders WHERE SenderID = :senderID") String findPhoneBySenderID(@Bind("senderID") String senderID); /* * close with no args is used to close the connection */ void close(); }

FedEx への接続を開く

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

There are five pieces of information needed in order to authenticate its actions with the FedEx service. This information is below.

  • Server: This controls the URL where the requests should be sent. Common testing options for this are: "https://gatewaybeta.fedex.com:443/xml", "https://wsbeta.fedex.com:443/xml", "https://gatewaybeta.fedex.com:443/web-service", and "https://wsbeta.fedex.com:443/web-service"
  • DeveloperKey: This is the identifier part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • Password: This is the secret part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • AccountNumber: This valid 9-digit FedEx account number is used for logging into the FedEx server.
  • MeterNumber: This value is used for submitting requests to FedEx. This value will be provided to you by FedEx after registration.
  • PrintLabelLocation: This property is required if one intends to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

The Cache Database

Many of the useful tasks available from FedEx require a lot of data. To ensure this data is easy to input and recall later, utilizes a cache database to make these requests. You must set the cache connection properties:

  • CacheProvider: The specific database you are using to cache with. For example, org.sqlite.JDBC.
  • CacheConnection: The connection string to be passed to the cache provider. For example, jdbc:sqlite:C:\users\username\documents\fedexcache.db

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

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

java -jar cdata.jdbc.fedex.jar

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

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

jdbc:fedex:Server='https://gatewaybeta.fedex.com:443/xml';DeveloperKey='alsdkfjpqoewiru';Password='zxczxqqtyiuowkdlkn';AccountNumber='110371337';MeterNumber='240134349'; PrintLabelLocation='C:\users\username\documents\mylabels';CacheProvider='org.sqlite.JDBC';CacheConnection='jdbc:sqlite:C:\users\username\documents\fedexcache.db';

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:fedex:Server='https://gatewaybeta.fedex.com:443/xml';DeveloperKey='alsdkfjpqoewiru';Password='zxczxqqtyiuowkdlkn';AccountNumber='110371337';MeterNumber='240134349'; PrintLabelLocation='C:\users\username\documents\mylabels';CacheProvider='org.sqlite.JDBC';CacheConnection='jdbc:sqlite:C:\users\username\documents\fedexcache.db';"); MySendersDAO dao = dbi.open(MySendersDAO.class); //do stuff with the DAO dao.close();

FedEx Data について

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

//disply the result of our 'find' method String phone = dao.findPhoneBySenderID("ab26f704-5edf-4a9f-9e4c-25"); System.out.println(phone);

FedEx Data の書き方

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

//add a new entry to the Senders entity dao.insert(newSenderID, newPhone);

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

 
 
ダウンロード