We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Create a Data Access Object for Sage 50 UK Data using JDBI
A brief overview of creating a SQL Object API for Sage 50 UK data in JDBI.
JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for Sage 50 UK integrates connectivity to live Sage 50 UK data in Java applications. By pairing these technologies, you gain simple, programmatic access to Sage 50 UK data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read and write Sage 50 UK data.
Create a DAO for the Sage 50 UK TradingAccounts Entity
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();
}
Open a Connection to 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:
- If you have not already done so, open the Sage 50 UK software.
- Click Tools -> Internet Options.
- Select the SData Settings tab.
- 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.
- 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.

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();
Read 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);
Write 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.