VOOZH about

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

⇱ Query CSV Data in DataGrip


Query CSV Data in DataGrip

πŸ‘ Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Create a Data Source for CSV in DataGrip and use SQL to query live CSV data.

DataGrip is a database IDE that allows SQL developers to query, create, and manage databases. When paired with the CData JDBC Driver for CSV, DataGrip can work with live CSV data. This article shows how to establish a connection to CSV data in DataGrip.

Create a New Driver Definition for CSV

The steps below describe how to create a new Data Source in DataGrip for CSV.

  1. In DataGrip, click File -> New > Project and name the project πŸ‘ Creating a new DataGrip project.
  2. In the Database Explorer, click the plus icon () and select Driver. πŸ‘ Adding a new Driver.
  3. In the Driver tab:
    • Set Name to a user-friendly name (e.g. "CData CSV Driver")
    • Set Driver Files to the appropriate JAR file. To add the file, click the plus (), select "Add Files," navigate to the "lib" folder in the driver's installation directory and select the JAR file (e.g. cdata.jdbc.csv.jar).
    • Set Class to cdata.jdbc.csv.CSV.jar
  4. Click "Apply" then "OK" to save the Connection πŸ‘ A configured Driver (Salesforce is shown).

Configure a Connection to CSV

  1. Once the connection is saved, click the plus (), then "Data Source" then "CData CSV Driver" to create a new CSV Data Source.
  2. In the new window, configure the connection to CSV with a JDBC URL.

    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.

    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.

    πŸ‘ Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)
  3. Set URL to the connection string, e.g.,
    jdbc:csv:URI=/PATH/TO/MyCSVFilesFolder;
  4. Click "Apply" and "OK" to save the connection string πŸ‘ A configured Data Source (Salesforce is shown).

At this point, you will see the data source in the Data Explorer.

Execute SQL Queries Against CSV

To browse through the CSV entities (available as tables) accessible through the JDBC Driver, expand the Data Source.

πŸ‘ Exploring the data (Salesforce is shown.)

To execute queries, right click on any table and select "New" -> "Query Console."

πŸ‘ Opening a new Query Console.

In the Console, write the SQL query you wish to execute. For example:

SELECT City, SUM(TotalDue) FROM Customer GROUP BY City
πŸ‘ Querying with SQL (Salesforce is shown.)

Download a free, 30-day trial of the CData JDBC Driver for CSV and start working with your live CSV data in DataGrip. Reach out to our Support Team if you have any questions.

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.