JDBC Driver for SAP Gateway

Build 22.0.8462

Establishing a Connection

Creating a JDBC Data Source

You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for SAP Gateway consists of three basic steps:

  • Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
  • Provide the driver class. For example:
    cdata.jdbc.sapgateway.SAPGatewayDriver
  • Provide the JDBC URL. For example:
    jdbc:sapgateway:InitiateOAuth=GETANDREFRESH;User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/
    
    or
    
    jdbc:cdata:sapgateway:InitiateOAuth=GETANDREFRESH;User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/

    The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:sapgateway:" or "jdbc:cdata:sapgateway:" and can include any of the connection properties in name-value pairs separated with semicolons.

Connecting to SAP Gateway

Set the following connection properties to access SAP Gateway tables.

  • Url: Set this to the URL of your environment, or to the full URL of the service. For example, the full url might appear as: https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/. In this example, the environment url would just be: https://sapes5.sapdevcenter.com. Add any additional properties using the CustomUrlParams property.
  • Namespace: Set the appropriate Service Namespace. In the example above, IWBEP is the namespace. It is optional if the full url to the service is specified.
  • Service: Set this to the service you want to retrieve data from. In the example above, the service is GWSAMPLE_BASIC. It is not required if the full url is specified.
  • CustomUrlParams: Set this to any required additional properties that need to be included with the HTTP request, for example sap-client=001&sap-language=EN.

Authenticating to SAP Gateway

SAP Gateway allows both basic and OAuth 2.0 authentication. You can use basic authentication to connect to your own account, or you can use OAuth to enable other users to retrieve data from your service with their accounts.

Basic

In basic authentication, you use your login credentials to connect. Set the following properties:

  • AuthScheme: Set this to Basic.
  • User: This is the username you use to log in to SAP Gateway.
  • Password: This is the password you use to log in to SAP Gateway.

OAuth

See Using OAuth Authentication for an authentication guide. You can connect without setting any connection properties for your user credentials. Set InitiateOAuth to GETANDREFRESH to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.

When you connect, the driver opens the SAP Gateway OAuth endpoint in your default browser. Log in and grant permissions to the driver. The driver then completes the following OAuth process:

  1. Extracts the access token from the callback URL and authenticates requests.
  2. Obtains a new access token when the old one expires.
  3. Saves OAuth values in OAuthSettingsLocation to be persisted across connections.

See Using OAuth Authentication for other OAuth authentication flows. In this OAuth flow, you can connect without setting any connection properties for your user credentials. Click Connect to open the SAP Gateway OAuth endpoint. Log in and grant permissions to the driver. The driver then completes the OAuth process.

API Key

To connect using an ApiKey, set the APIKey property, and you are ready to connect.

In order to acquire an APIKey, open the Developer Portal and select the Product or Service for which you have published the API. Then, click on Subscribe > Create a new Application. After filling the necessary information and creating the application, the Application Key is going to be displayed. You can copy this value into the APIKey connection property.

You may set the AuthScheme to Token to enforce the Token based Authentication scheme.

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462