Ready to get started?

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

Download Now

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

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

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

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

Dynamics NAV への接続を開く

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

Before you can connect, OData Services will need to be enabled on the server. Once OData Services are enabled, you will be able to query any Services that are published on the server.

The User and Password properties, under the Authentication section, must be set to valid Dynamics NAV user credentials. In addition, you will need to specify a URL to a valid Dynamics NAV server organization root and a ServerInstance. If there is not a Service Default Company for the server, you will need to set the Company as well.

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

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

java -jar cdata.jdbc.dynamicsnav.jar

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

A connection string for Dynamics NAV will typically look like the following:

jdbc:dynamicsnav:http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71;

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:dynamicsnav:http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71;"); MyCustomerDAO dao = dbi.open(MyCustomerDAO.class); //do stuff with the DAO dao.close();

Dynamics NAV Data について

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

//disply the result of our 'find' method String prices_Including_VAT = dao.findPrices_Including_VATByName("Bob"); System.out.println(prices_Including_VAT);

Dynamics NAV Data の書き方

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

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

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

 
 
ダウンロード