![]() |
VOOZH | about |
JRuby is a high-performance, stable, fully threaded Java implementation of the Ruby programming language. The CData JDBC Driver for SAP Netweaver Gateway makes it easy to integrate connectivity to live SAP Netweaver Gateway data in JRuby. This article shows how to create a simple JRuby app that connects to SAP Netweaver Gateway data, executes a query, and displays the results.
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 SAP Netweaver Gateway\lib).
JRuby natively supports JDBC, so you can easily connect to SAP Netweaver Gateway and execute SQL queries. Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class.
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. In addition to authenticating, set the following connection properties to access SAP Gateway tables.
In basic authentication, you use your login credentials to connect. Set the following properties:
You can connect to SAP Gateway using the embedded OAuth connectivity (without setting any additional authentication connection properties). When you connect, the OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.
For assistance in constructing the JDBC URL, use the connection string designer built into the SAP Netweaver Gateway JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.sapgateway.jar
Fill in the connection properties and copy the connection string to the clipboard.
👁 Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)Below is a typical JDBC connection string for SAP Netweaver Gateway:
jdbc:sapgateway:User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/;InitiateOAuth=GETANDREFRESH;
Create a new Ruby file (for example: SAPGatewaySelect.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 SAP Netweaver Gateway 2018/lib/cdata.jdbc.sapgateway.jar'
url = "jdbc:sapgateway:User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/;InitiateOAuth=GETANDREFRESH;"
conn = java.sql.DriverManager.getConnection(url)
stmt = conn.createStatement
rs = stmt.executeQuery("SELECT ProductID, Quantity FROM SalesOrderLineItems")
while (rs.next) do
puts rs.getString(1) + ' ' + rs.getString(2)
end
With the file completed, you are ready to display your SAP Netweaver Gateway data with JRuby. To do so, simply run your file from the command line:
jruby -S SAPGatewaySelect.rb
Writing SQL-92 queries to SAP Netweaver Gateway allows you to quickly and easily incorporate SAP Netweaver Gateway data into your own JRuby applications. Download a free trial today!
Download a free trial of the SAP Netweaver Gateway Driver to get started:
Download NowLearn more:
👁 SAP Netweaver Gateway IconRapidly create and deploy powerful Java applications that integrate with SAP Netweaver Gateway.