Skip to content

Instantly share code, notes, and snippets.

@gaurish
Created February 26, 2022 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaurish/6eec42d62ee40b15da105be8eda9a6fc to your computer and use it in GitHub Desktop.
Save gaurish/6eec42d62ee40b15da105be8eda9a6fc to your computer and use it in GitHub Desktop.
this works
jruby-9.3.3.0 :002 > require 'java'
=> false
jruby-9.3.3.0 :004 > require Rails.root.join('vendor','snowflake-jdbc-3.13.14.jar')
=> false
jruby-9.3.3.0 :005 > ENV['SNOWFLAKE_DB_URL']
=> "jdbc:snowflake://xxxx.us-east-1.snowflakecomputing.com?user=user@gmail.com&password=password$&db=LARGE_SAMPLE_DATA&schema=USERS&warehouse=POC"
require 'java'
require Rails.root.join('vendor','snowflake-jdbc-3.13.14.jar')
class FetchEnqueueJob < ApplicationJob
def perform
connection = java.sql.DriverManager.getConnection(ENV['SNOWFLAKE_DB_URL'])
statement = connection.create_statement
# >Traceback (most recent call last):
# Java::JavaSql::SQLException (No suitable driver found for jdbc:snowflake://xxxx.us-east-1.snowflakecomputing.com?user=user@gmail.com&password=password$&db=LARGE_SAMPLE_DATA&schema=USERS&warehouse=POC)
end
require 'java'
require '/Users/gaurish/code/projects/snowflake-jdbc-3.13.14.jar'
connection_str = ENV['SNOWFLAKE_DB_URL']
conn = java.sql.DriverManager.getConnection(connection_str)
statement = conn.createStatement
query = 'select id, email from users'
result_set = statement.execute_query(query)
col_count = result_set.get_meta_data.get_column_count
while (result_set.next) do
(1..col_count).each do |i|
print "#{i} => #{result_set.get_string(i)}}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment