Ready to get started?

Download a free trial of the Sage 300 Driver to get started:

 Download Now

Learn more:

Sage 300 Icon Sage 300 JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Sage 300.

How to work with Sage 300 Data in Apache Spark using SQL



Access and process Sage 300 Data in Apache Spark using the CData JDBC Driver.

Apache Spark is a fast and general engine for large-scale data processing. When paired with the CData JDBC Driver for Sage 300, Spark can work with live Sage 300 data. This article describes how to connect to and query Sage 300 data from a Spark shell.

The CData JDBC Driver offers unmatched performance for interacting with live Sage 300 data due to optimized data processing built into the driver. When you issue complex SQL queries to Sage 300, the driver pushes supported SQL operations, like filters and aggregations, directly to Sage 300 and utilizes the embedded SQL engine to process unsupported operations (often SQL functions and JOIN operations) client-side. With built-in dynamic metadata querying, you can work with and analyze Sage 300 data using native data types.

Install the CData JDBC Driver for Sage 300

Download the CData JDBC Driver for Sage 300 installer, unzip the package, and run the JAR file to install the driver.

Start a Spark Shell and Connect to Sage 300 Data

  1. Open a terminal and start the Spark shell with the CData JDBC Driver for Sage 300 JAR file as the jars parameter: $ spark-shell --jars /CData/CData JDBC Driver for Sage 300/lib/cdata.jdbc.sage300.jar
  2. With the shell running, you can connect to Sage 300 with a JDBC URL and use the SQL Context load() function to read a table.

    Sage 300 requires some initial setup in order to communicate over the Sage 300 Web API.

    • Set up the security groups for the Sage 300 user. Give the Sage 300 user access to the option under Security Groups (per each module required).
    • Edit both web.config files in the /Online/Web and /Online/WebApi folders; change the key AllowWebApiAccessForAdmin to true. Restart the webAPI app-pool for the settings to take.
    • Once the user access is configured, click https://server/Sage300WebApi/ to ensure access to the web API.

    Authenticate to Sage 300 using Basic authentication.

    Connect Using Basic Authentication

    You must provide values for the following properties to successfully authenticate to Sage 300. Note that the provider reuses the session opened by Sage 300 using cookies. This means that your credentials are used only on the first request to open the session. After that, cookies returned from Sage 300 are used for authentication.

    • Url: Set this to the url of the server hosting Sage 300. Construct a URL for the Sage 300 Web API as follows: {protocol}://{host-application-path}/v{version}/{tenant}/ For example, http://localhost/Sage300WebApi/v1.0/-/.
    • User: Set this to the username of your account.
    • Password: Set this to the password of your account.

    Built-in Connection String Designer

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

    java -jar cdata.jdbc.sage300.jar

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

    Configure the connection to Sage 300, using the connection string generated above.

    scala> val sage300_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:sage300:User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;").option("dbtable","OEInvoices").option("driver","cdata.jdbc.sage300.Sage300Driver").load()
  3. Once you connect and the data is loaded you will see the table schema displayed.
  4. Register the Sage 300 data as a temporary table:

    scala> sage300_df.registerTable("oeinvoices")
  5. Perform custom SQL queries against the Data using commands like the one below:

    scala> sage300_df.sqlContext.sql("SELECT InvoiceUniquifier, ApprovedLimit FROM OEInvoices WHERE AllowPartialShipments = Yes").collect.foreach(println)

    You will see the results displayed in the console, similar to the following:

Using the CData JDBC Driver for Sage 300 in Apache Spark, you are able to perform fast and complex analytics on Sage 300 data, combining the power and utility of Spark with your data. Download a free, 30 day trial of any of the 200+ CData JDBC Drivers and get started today.