今すぐお試しください!

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

今すぐダウンロード

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

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

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

Sage 50 UK TradingAccounts 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 MyTradingAccountsDAO { //insert new data into Sage 50 UK @SqlUpdate("INSERT INTO TradingAccounts (TradingAccountUUID, FinanceBalance) values (:tradingAccountUUID, :financeBalance)") void insert(@Bind("tradingAccountUUID") String tradingAccountUUID, @Bind("financeBalance") String financeBalance); //request specific data from Sage 50 UK (String type is used for simplicity) @SqlQuery("SELECT FinanceBalance FROM TradingAccounts WHERE TradingAccountUUID = :tradingAccountUUID") String findFinanceBalanceByTradingAccountUUID(@Bind("tradingAccountUUID") String tradingAccountUUID); /* * close with no args is used to close the connection */ void close(); }

Sage 50 UK への接続を開く

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Sage 50 UK.

Note: Only Sage 50 UK 2012 and above are supported.

The User and Password properties, under the Connection section, must be set to valid Sage 50 UK user credentials. These values will be the same used to log in to the Sage 50 UK software.

Additionally, the URL property, under the Connection section, will need to be set to the address of the company dataset desired. To obtain the address, do the following:

  1. If you have not already done so, open the Sage 50 UK software.
  2. Click Tools -> Internet Options.
  3. Select the SData Settings tab.
  4. Click the Details button next to Sage 50 Accounts. A window is displayed containing a list of company names along with the address to their corresponding datasets.
  5. Set the URL property to the value in the address field next to the company desired.

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

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

java -jar cdata.jdbc.sage50uk.jar

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

A connection string for Sage 50 UK will typically look like the following:

jdbc:sage50uk:URL=http://your-server:5493/sdata/accounts50/GCRM/your-address;User=Manager;

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:sage50uk:URL=http://your-server:5493/sdata/accounts50/GCRM/your-address;User=Manager;"); MyTradingAccountsDAO dao = dbi.open(MyTradingAccountsDAO.class); //do stuff with the DAO dao.close();

Sage 50 UK Data について

With the connection open to Sage 50 UK, simply call the previously defined method to retrieve data from the TradingAccounts entity in Sage 50 UK.

//disply the result of our 'find' method String financeBalance = dao.findFinanceBalanceByTradingAccountUUID("c2ef66a5-a545-413b-9312-79a53caadbc4"); System.out.println(financeBalance);

Sage 50 UK Data の書き方

It is also simple to write data to Sage 50 UK, using the previously defined method.

//add a new entry to the TradingAccounts entity dao.insert(newTradingAccountUUID, newFinanceBalance);

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

 
 
ダウンロード