JRuby からSage US Data にデータ連携

リアルタイムSage US data に連携するシンプルなJRuby アプリケーションを作成します。

JRuby はRuby プログラミング言語の高性能で安定した、完全にスレッド化されたJava 実装です。CData JDBC Driver for Sage US を使用すると、JRuby からリアルタイムSage US data へのデータ連携を簡単に実装できます。ここでは、Sage US data に接続し、クエリを実行して結果を表示する簡単なJRuby アプリを作成する方法を説明します。

Sage US Data にJDBC で接続

Before creating the app, note the installation location for the JAR file for the JDBC Driver (typically C:\Program Files\CDatat\CData JDBC Driver for Sage US\lib).

JRuby natively supports JDBC, so you can easily connect to Sage US and execute SQL queries.Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class.

The Application Id and Company Name connection string options are required to connect to Sage as a data source. You can obtain an Application Id by contacting Sage directly to request access to the Sage 50 SDK.

Sage must be installed on the machine. The Sage.Peachtree.API.dll and Sage.Peachtree.API.Resolver.dll assemblies are required. These assemblies are installed with Sage in C:\Program Files\Sage\Peachtree\API\. Additionally, the Sage SDK requires .NET Framework 4.0 and is only compatible with 32-bit applications. To use the Sage SDK in Visual Studio, set the Platform Target property to "x86" in Project -> Properties -> Build.

You must authorize the application to access company data: To authorize your application to access Sage, restart the Sage application, open the company you want to access, and connect with your application. You will then be prompted to set access permissions for the application in the resulting dialog.

While the compiled executable will require authorization only once, during development you may need to follow this process to reauthorize a new build. To avoid restarting the Sage application when developing with Visual Studio, click Build -> Configuration Manager and uncheck "Build" for your project.

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

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

java -jar cdata.jdbc.sage50us.jar

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

Below is a typical JDBC connection string for Sage US:

jdbc:sage50us:ApplicationId=8dfafu4V4ODmh1fM0xx;CompanyName=Bellwether Garden Supply - Premium;

Sage US Data への接続性を持つJRuby アプリを作成

Create a new Ruby file (for example: Sage50USSelect.rb) and open it in a text editor.Copy the following code into your file:

require 'java' require 'rubygems' require 'C:/Program Files/CData/CData JDBC Driver for Sage US 2018/lib/cdata.jdbc.sage50us.jar' url = "jdbc:sage50us:ApplicationId=8dfafu4V4ODmh1fM0xx;CompanyName=Bellwether Garden Supply - Premium;" conn = java.sql.DriverManager.getConnection(url) stmt = conn.createStatement rs = stmt.executeQuery("SELECT Name, LastInvoiceAmount FROM Customer") while (rs.next) do puts rs.getString(1) + ' ' + rs.getString(2) end

With the file completed, you are ready to display your Sage US data with JRuby.To do so, simply run your file from the command line:

jruby -S Sage50USSelect.rb

Writing SQL-92 queries to Sage US allows you to quickly and easily incorporate Sage US data into your own JRuby applications.Download a free trial today!

 
 
ダウンロード