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

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

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

Dynamics AX CustInvoiceTrans 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 MyCustInvoiceTransDAO { //insert new data into Dynamics AX @SqlUpdate("INSERT INTO CustInvoiceTrans (Qty, Qty) values (:qty, :qty)") void insert(@Bind("qty") String qty, @Bind("qty") String qty); //request specific data from Dynamics AX (String type is used for simplicity) @SqlQuery("SELECT Qty FROM CustInvoiceTrans WHERE Qty = :qty") String findQtyByQty(@Bind("qty") String qty); /* * close with no args is used to close the connection */ void close(); }

Dynamics AX への接続を開く

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

To connect to DynamicsAX, specify User, Domain, and ObjectServer. You can also surface tables for a specific Company; when this property is blank, the default company is used.

Alternatively, you can use the .NET Business Connector to connect on behalf of DynamicsAX users. You can obtain the ProxyUser and ProxyDomain properties on the System service accounts form: Click System Administration -> Setup -> System -> System Service Accounts. Additionally, set ProxyPassword.

By default, only transaction data and base information from the TRANSACTION and MAIN table groups is returned. You can specify which groups to return with TableGroups.

Set Language to use the same language you use in your DynamicsAX labels.


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

java -jar cdata.jdbc.dynamicsax.jar

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

A connection string for Dynamics AX 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:dynamicsax:User=MyUser;Domain=MyDomain;objectserver=MicrosoftDynamicsAX@WIN-1IP52JPQVJS:2712;"); MyCustInvoiceTransDAO dao = dbi.open(MyCustInvoiceTransDAO.class); //do stuff with the DAO dao.close();

Dynamics AX Data について

With the connection open to Dynamics AX, simply call the previously defined method to retrieve data from the CustInvoiceTrans entity in Dynamics AX.

//disply the result of our 'find' method String qty = dao.findQtyByQty("2000"); System.out.println(qty);

Dynamics AX Data の書き方

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

//add a new entry to the CustInvoiceTrans entity dao.insert(newQty, newQty);

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