Connect to Sage 50 UK Data in JRuby

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Sage 50 UK JDBC Driver

Complete read-write access to Sage 50 UK enables developers to search (Customers, Transactions, Invoices, Sales Receipts, etc.), update items, edit customers, and more, from any Java/J2EE application.



Create a simple JRuby app with access to live Sage 50 UK data.

JRuby is a high-performance, stable, fully threaded Java implementation of the Ruby programming language. The CData JDBC Driver for Sage 50 UK makes it easy to integrate connectivity to live Sage 50 UK data in JRuby. This article shows how to create a simple JRuby app that connects to Sage 50 UK data, executes a query, and displays the results.

Configure a JDBC Connection to Sage 50 UK Data

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

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

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.

Built-in Connection String Designer

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.

Below is a typical JDBC connection string for Sage 50 UK:

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

Create a JRuby App with Connectivity to Sage 50 UK Data

Create a new Ruby file (for example: Sage50UKSelect.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 50 UK 2018/lib/cdata.jdbc.sage50uk.jar' url = "jdbc:sage50uk:URL=http://your-server:5493/sdata/accounts50/GCRM/your-address;User=Manager;" conn = java.sql.DriverManager.getConnection(url) stmt = conn.createStatement rs = stmt.executeQuery("SELECT Name, FinanceBalance FROM TradingAccounts") while (rs.next) do puts rs.getString(1) + ' ' + rs.getString(2) end

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

jruby -S Sage50UKSelect.rb

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