Ready to get started?

Learn more about the CData JDBC Driver for Dynamics 365 Business Central or download a free trial:

Download Now

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

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

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

Dynamics 365 Business Central Accounts 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 MyAccountsDAO { //insert new data into Dynamics 365 Business Central @SqlUpdate("INSERT INTO Accounts (Name, Name) values (:name, :name)") void insert(@Bind("name") String name, @Bind("name") String name); //request specific data from Dynamics 365 Business Central (String type is used for simplicity) @SqlQuery("SELECT Name FROM Accounts WHERE Name = :name") String findNameByName(@Bind("name") String name); /* * close with no args is used to close the connection */ void close(); }

Dynamics 365 Business Central への接続を開く

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Dynamics 365 Business Central.

To authenticate to Dynamics 365 Business Central, you must provide the User and AccessKey properties.

To obtain the User and AccessKey values, navigate to the Users page in Dynamics 365 Business Central and then click on Edit. The User Name and Web Service Access Key values are what you will enter as the User and AccessKey connection string properties. Note that the User Name is not your email address. It is a shortened user name.

To connect to data, specify OrganizationUrl. If you have multiple companies in your organization, you must also specify the Company to indicate which company you would like to connect to. Company does not need to be specified if you have only one company.

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

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

java -jar cdata.jdbc.d365businesscentral.jar

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

A connection string for Dynamics 365 Business Central will typically look like the following:

jdbc:d365businesscentral:OrganizationUrl=https://myaccount.financials.dynamics.com/;

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:d365businesscentral:OrganizationUrl=https://myaccount.financials.dynamics.com/;"); MyAccountsDAO dao = dbi.open(MyAccountsDAO.class); //do stuff with the DAO dao.close();

Dynamics 365 Business Central Data について

With the connection open to Dynamics 365 Business Central, simply call the previously defined method to retrieve data from the Accounts entity in Dynamics 365 Business Central.

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

Dynamics 365 Business Central Data の書き方

It is also simple to write data to Dynamics 365 Business Central, using the previously defined method.

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

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

 
 
ダウンロード