Create a Data Access Object for SAP Business Warehouse Data using JDBI

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
A brief overview of creating a SQL Object API for SAP Business Warehouse 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 Warehouse integrates connectivity to live SAP Business Warehouse data in Java applications. By pairing these technologies, you gain simple, programmatic access to SAP Business Warehouse data. This article explains how to build a basic Data Access Object (DAO) and the accompanying code to read SAP Business Warehouse data.

Create a DAO for the SAP Business Warehouse Sales 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 MySalesDAO {
  //request specific data from SAP Business Warehouse (String type is used for simplicity)
  @SqlQuery("SELECT City FROM Sales WHERE Country = :country")
  String findCityByCountry(@Bind("country") String country);

  /*
   * close with no args is used to close the connection
   */
  void close();
}

Open a Connection to SAP Business Warehouse

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

To connect to SAP Business Warehouse, set the URL property to a valid SAP Business Warehouse server base URL. The driver must connect to SAP Business Warehouse instances hosted over HTTP with XMLA access.

The driver supports the following authentication schemes via the AuthScheme property:

  • None: Anonymous authentication, if available on the server.
  • Basic: Set User and Password and set AuthScheme to Basic.
  • Kerberos: See the Using Kerberos section of the help documentation for the required Kerberos properties.

By default, the driver attempts to negotiate SSL/TLS by checking the server's certificate against the system's trusted certificate store. To specify another certificate, see the SSLServerCert property for the available formats.

Built-in Connection String Designer

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

java -jar cdata.jdbc.sapbusinesswarehouse.jar

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

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

jdbc:sapbusinesswarehouse:URL=https://mysapserver:8000;AuthScheme=Basic;User=username;Password=password;

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:sapbusinesswarehouse:URL=https://mysapserver:8000;AuthScheme=Basic;User=username;Password=password;");
MySalesDAO dao = dbi.open(MySalesDAO.class);

//do stuff with the DAO

dao.close();

Read SAP Business Warehouse Data

With the connection open to SAP Business Warehouse, simply call the previously defined method to retrieve data from the Sales entity in SAP Business Warehouse.

//disply the result of our 'find' method
String city = dao.findCityByCountry("US");
System.out.println(city);

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

Ready to get started?

Download a free trial of the SAP Business Warehouse Driver to get started:

 Download Now

Learn more:

SAP Business Warehouse Icon SAP Business Warehouse JDBC Driver

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