今すぐお試しください!

製品の詳細CData JDBC Driver for MYOB AccountRight を確認して、無償評価版をダウンロード:

今すぐダウンロード

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

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

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

MYOB AccountRight 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 MYOB AccountRight @SqlUpdate("INSERT INTO Accounts (Type, Name) values (:type, :name)") void insert(@Bind("type") String type, @Bind("name") String name); //request specific data from MYOB AccountRight (String type is used for simplicity) @SqlQuery("SELECT Name FROM Accounts WHERE Type = :type") String findNameByType(@Bind("type") String type); /* * close with no args is used to close the connection */ void close(); }

MYOB AccountRight への接続を開く

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

These properties are required when connecting to a company file (both for Cloud and On-Premise instances).

  • CompanyFileId: You can find this by starting MYOB, opening your data file, and selecting Help -> About MYOB
  • User: The username associated with your company file.
  • Password: The password associated with your company file.

Connecting to a Cloud Instance

To connect to a cloud instance of MYOB, you can use the embedded OAuth credentials or create an OAuth app with MYOB. This process is detailed in the Help documentation.

Connecting to an On-Premise instance:

When connecting to an on-premise instance, you will need to set the following connection property in addition to those above:

  • InitiateOauth: Set this to OFF.
  • Url: The Url of your MYOB instance.

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

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

java -jar cdata.jdbc.myob.jar

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

A connection string for MYOB AccountRight will typically look like the following:

jdbc:myob:OAuthClientId=YourClientId; OAuthClientSecret=YourClientSecret; CompanyFileId=yourCompanyFileId; CallbackURL=http://localhost:33333; User=companyFileUser; Password=companyFilePassword; InitiateOAuth=GETANDREFRESH

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:myob:OAuthClientId=YourClientId; OAuthClientSecret=YourClientSecret; CompanyFileId=yourCompanyFileId; CallbackURL=http://localhost:33333; User=companyFileUser; Password=companyFilePassword; InitiateOAuth=GETANDREFRESH"); MyAccountsDAO dao = dbi.open(MyAccountsDAO.class); //do stuff with the DAO dao.close();

MYOB AccountRight Data について

With the connection open to MYOB AccountRight, simply call the previously defined method to retrieve data from the Accounts entity in MYOB AccountRight.

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

MYOB AccountRight Data の書き方

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

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

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

 
 
ダウンロード