VOOZH about

URL: https://www.cdata.com/kb/tech/csv-jdbc-spagobi.rst

⇱ Connect to CSV in SpagoBI


Connect to CSV in SpagoBI

πŸ‘ Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Create reports featuring live CSV data in SpagoBI Studio. Host CSV reports on SpagoBI Server.

The CData JDBC Driver for CSV enables you to connect to live CSV data from business intelligence and data mining tools that support the JDBC standard. This article shows how to integrate CSV data into a report in SpagoBI Studio and host it on SpagoBI Server.

Deploy the JDBC Driver in SpagoBI Server

Follow the steps to create a JDBC data source for CSV in SpagoBI Server.

  1. Copy the driver JAR into %CATALINA_BASE%/lib. These files are located in the lib subfolder of the installation directory.
  2. Add a CSV driver resource to the context. The following resource definition can be added to the GlobalNamingResources element in server.xml:

    <Resource name="jdbc/csv" auth="Container" type="javax.sql.DataSource" driverclassname="cdata.jdbc.csv.CSVDriver" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" maxactive="20" maxidle="10" maxwait="-1"/>
  3. Add the following resource link to give access to Web applications. For this article, add the following line to META-INF\context.xml for SpagoBI.
    <ResourceLink global="jdbc/csv" name="jdbc/csv" type="javax.sql.DataSource"/>
    
  4. Restart the server.

After adding the driver to the resources for the SpagoBI server, add the data source: In SpagoBI, click Resources -> Data Source -> Add and enter the following information:

  • Label: Enter a unique identifier for the driver.
  • Description: Enter a description for the driver.
  • Dialect: Select Default Dialect.
  • Read Only: Select the read-only option. This option determines whether the data source is the default database to save datasets created by the end user.
  • Type: Select JDBC.
  • URL: Enter the JDBC URL using the required connection string properties:

    Connecting to Local or Cloud-Stored (Box, Google Drive, Amazon S3, SharePoint) CSV Files

    CData Drivers let you work with CSV files stored locally and stored in cloud storage services like Box, Amazon S3, Google Drive, or SharePoint, right where they are.

    Setting connection properties for local files

    Set the URI property to local folder path.

    Setting connection properties for files stored in Amazon S3

    To connect to CSV file(s) within Amazon S3, set the URI property to the URI of the Bucket and Folder where the intended CSV files exist. In addition, at least set these properties:

    • AWSAccessKey: AWS Access Key (username)
    • AWSSecretKey: AWS Secret Key

    Setting connection properties for files stored in Box

    To connect to CSV file(s) within Box, set the URI property to the URI of the folder that includes the intended CSV file(s). Use the OAuth authentication method to connect to Box.

    Dropbox

    To connect to CSV file(s) within Dropbox, set the URI proprerty to the URI of the folder that includes the intended CSV file(s). Use the OAuth authentication method to connect to Dropbox. Either User Account or Service Account can be used to authenticate.

    SharePoint Online (SOAP)

    To connect to CSV file(s) within SharePoint with SOAP Schema, set the URI proprerty to the URI of the document library that includes the intended CSV file. Set User, Password, and StorageBaseURL.

    SharePoint Online REST

    To connect to CSV file(s) within SharePoint with REST Schema, set the URI proprerty to the URI of the document library that includes the intended CSV file. StorageBaseURL is optional. If not set, the driver will use the root drive. OAuth is used to authenticate.

    Google Drive

    To connect to CSV file(s) within Google Drive, set the URI property to the URI of the folder that includes the intended CSV file(s). Use the OAuth authentication method to connect and set InitiateOAuth to GETANDREFRESH.

    Built-in Connection String Designer

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

    java -jar cdata.jdbc.csv.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.)

    A typical JDBC URL is below:

    jdbc:csv:URI=/PATH/TO/MyCSVFilesFolder;
    
  • Driver: Enter the class name for the driver: cdata.jdbc.csv.CSVDriver
πŸ‘ The configuration for the CSV JDBC data source. (Salesforce is shown.)

Create Reports in SpagoBI Studio

Follow the steps below to populate reports based on CSV data in SpagoBI Studio. You will create a dataset that populates a chart with the results of an SQL query. In the next section, you will host this report on SpagoBI Server.

First, you will need to connect to CSV data from a report in SpagoBI Studio:

  1. In SpagoBI Studio, click File -> New -> Project and select Report Project in the Business Intelligence and Reporting Tools folder.
  2. Click File -> New -> Report and select Blank Report.
  3. In the Data Explorer view, right-click Data Sources and click New Data Source.
  4. Select JDBC Data Source and enter a name for the data source.
  5. Click Manage Drivers and click Add to add the driver JAR, cdata.jdbc.csv.jar. The driver JAR is located in the lib subfolder of the installation directory.
  6. In the Driver Class menu, select the driver class, cdata.jdbc.csv.CSVDriver.
  7. In the Database URL box, enter the JDBC URL. A typical JDBC URL is below:
    jdbc:csv:URI=/PATH/TO/MyCSVFilesFolder;
    
    See the "Getting Started" chapter of the driver help for a guide to obtaining the required connection properties. πŸ‘ The JDBC data source. (Salesforce is shown.)

After you have connected to CSV data, create a dataset that contains the results of an SQL query:

  1. Right-click the DataSet folder and click New Data Set. Select the JDBC data source for CSV and enter a name for the dataset.
  2. Build the SQL query. In this example, this query will be used to add a chart to the dashboard. For example:
    SELECT City, SUM(TotalDue) FROM Customer GROUP BY City
    
    πŸ‘ The query to be used to populate a chart. (Salesforce is shown.)

You can use the dataset to populate report objects. Follow the steps below to create a chart.

  1. In the Palette view, drag a chart onto the canvas.
  2. In the Select Chart Type tab, select a bar chart.
  3. In the Select Data tab, click the Use Data From option and select the CSV data set from the menu.
  4. Drag City from the table to the series for the x-axis.
  5. Drag TotalDue from the table to the series for the y-axis. πŸ‘ Columns in the dataset defined as the x- and y-axes for the chart. (Salesforce is shown.)

Host CSV Reports on SpagoBI Server

Follow the steps below to host documents based on live CSV data on SpagoBI Server. You will use the report you created in the previous section as a template. To enable report users to access the live data, create placeholder parameters to be replaced by the CSV JDBC data source on the server:

  1. If you have not already done so, open the Report Design perspective in SpagoBI Studio.
  2. In the Data Explorer view, right-click the Report Parameters folder and click New Parameter. Add the url parameter and assign an empty value to it. This parameter is a placeholder for the JDBC data source on the SpagoBI Server.
  3. Right-click the CSV data source and click Edit.
  4. In the Property Binding node, set the JDBC Driver URL binding property to the url parameter: Click the box for the property. In the Category section, select Report Parameters. Select All in the Subcategory section and double-click the parameter.

    You can also enter the following in the JavaScript syntax:

    params["url"].value
    
    πŸ‘ Placeholder values in the report for the JDBC data source on the server.

Next, create a new document for the report on SpagoBI Server.

  1. In SpagoBI Server, click Documents Development -> Create Document -> Generic Document. The Document Details page is displayed.
  2. To create the document, enter the following:
    • Label: Enter a unique identifier for the document.
    • Name: Enter a user-friendly name for the document.
    • Type: Select Report from the menu.
    • Engine: Select BIRT Report Engine.
    • Data Source: Select the CSV Data Source you created in Create a JDBC Data Source for CSV in SpagoBI Server.
  3. In the Show Document Templates section, select the folder where you want the document to be stored.
  4. In the Template section, click Choose File. Navigate to the folder containing your report project. Select the .rptdesign file.

    Note: You can find the path to the project in the project properties.

  5. Click the Save button.
πŸ‘ The document using the report as a template. (Salesforce is shown.)

When you run the report on the server, the placeholder url parameter is replaced with the JDBC URL defined on the server.

πŸ‘ The chart running on the SpagoBI Server. (Salesforce is shown.)

Ready to get started?

Download a free trial of the CSV Driver to get started:

 Download Now

Learn more:

πŸ‘ CSV/TSV Files Icon
CSV JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with delimited flat-file (CSV/TSV) data.