DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • The SPACE Framework for Developer Productivity
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Building a Flask Web Application With Docker: A Step-by-Step Guide

Trending

  • The SPACE Framework for Developer Productivity
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  1. DZone
  2. Data Engineering
  3. Data
  4. Connect to Snowflake Data in JRuby

Connect to Snowflake Data in JRuby

Create a simple JRuby app with access to live Snowflake data.

Jerod Johnson user avatar by
Jerod Johnson
·
Updated Apr. 17, 19 · Tutorial
Like (4)
Save
Tweet
Share
13.52K Views

Join the DZone community and get the full member experience.

Join For Free

JRuby is a high-performance, stable, fully-threaded Java implementation of the Ruby programming language. The CData JDBC Driver for Snowflake makes it easy to integrate connectivity to live Snowflake data in JRuby. This article shows how to create a simple JRuby app that connects to Snowflake data, executes a query, and displays the results.

Configure a JDBC Connection to Snowflake Data

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 Snowflake\lib).

JRuby natively supports JDBC, so you can easily connect to Snowflake and execute SQL queries. Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class. Below is a typical JDBC connection string for Snowflake:

jdbc:snowflake:User=Admin;Password=test123;Server=localhost;Database=Northwind;Warehouse=TestWarehouse;Account=Test


To connect to Snowflake, set the User, Password, and AuthScheme properties.

In addition, set Account to the Snowflake account and set URL to the URL of the Snowflake instance (i.e.: https://myaccount.snowflakecomputing.com).

Last, set Warehouse, Database, and Schema to the corresponding Snowflake values.

See the Getting Started guide in the CData driver documentation for more information.

Create a JRuby App With Connectivity to Snowflake Data

Create a new Ruby file (for example, SnowflakeSelect.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 Snowflake 2018/lib/cdata.jdbc.snowflake.jar'

url = "jdbc:snowflake:User=Admin;Password=test123;Server=localhost;Database=Northwind;Warehouse=TestWarehouse;Account=Tester1;"
conn = java.sql.DriverManager.getConnection(url)
stmt = conn.createStatement
rs = stmt.executeQuery("SELECT Id, ProductName FROM Products")
while (rs.next) do
puts rs.getString(1) + ' ' + rs.getString(2)
end


With the file completed, you are ready to display your Snowflake data with JRuby. To do so, simply run your file from the command line: 

jruby -S SnowflakeSelect.rb


Writing SQL-92 queries to Snowflake allows you to quickly and easily incorporate Snowflake data into your own JRuby applications. Download a free trial today!

Jruby Data (computing)

Published at DZone with permission of Jerod Johnson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • The SPACE Framework for Developer Productivity
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Building a Flask Web Application With Docker: A Step-by-Step Guide

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: