Create a Data Access Object for SAP Business One DI Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

SAP Business One DI JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with SAP Business One DI.



A brief overview of creating a SQL Object API for SAP Business One DI 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 SAP Business One DI integrates connectivity to live SAP Business One DI data in Java applications. By pairing these technologies, you gain simple, programmatic access to SAP Business One DI data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read SAP Business One DI data.

Create a DAO for the SAP Business One DI OACT 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 MyOACTDAO { //request specific data from SAP Business One DI (String type is used for simplicity) @SqlQuery("SELECT AcctName FROM OACT WHERE AcctName = :acctName") String findAcctNameByAcctName(@Bind("acctName") String acctName); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to SAP Business One DI

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to SAP Business One DI.

To connect to SAP Business One DI data, specify the following connection properties:

  • DBServerType: The type of server being connected to.
  • Server: The name or IP address of the Business One DI server to connect to.
  • CompanyDB: The company to connect to.
  • User: The username used when connecting to the LicenseServer.
  • Password: The password used when connecting to the LicenseServer.
  • LicenseServer (optional): Set this if your License Server is different from the Server.
  • UseTrusted (optional): Set to TRUE to connect using Windows credentials.

Built-in Connection String Designer

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

java -jar cdata.jdbc.sapbusinessonedi.jar

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

A connection string for SAP Business One DI will typically look like the following:

jdbc:sapbusinessonedi:Server=ServerName;DBServerType=MSSQL_2016;CompanyDB=SBODemoCA;User=manager;Password=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:sapbusinessonedi:Server=ServerName;DBServerType=MSSQL_2016;CompanyDB=SBODemoCA;User=manager;Password=manager;"); MyOACTDAO dao = dbi.open(MyOACTDAO.class); //do stuff with the DAO dao.close();

Read SAP Business One DI Data

With the connection open to SAP Business One DI, simply call the previously defined method to retrieve data from the OACT entity in SAP Business One DI.

//disply the result of our 'find' method String acctName = dao.findAcctNameByAcctName("account_name"); System.out.println(acctName);

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