Connecting to Snowflake using Python and Java — Part II

viswanath thatha
Analytics Vidhya
Published in
2 min readNov 4, 2020

--

Connecting to snowflake with Java

There are different ways one can connect to snowflake data warehouse programmatically. We have already seen how to connect to snowflake data warehouse using Python and different functionalities here in Part I and to basics of Snowflake here.

Now we will see how to connect to snowflake using Java. For connecting to snowflake using Java, we will need snowflake JDBC driver. I have used “snowflake-jdbc-3.10.2.jar” which can be downloaded from official documentation page.

We will first import the required libraries

Next, we will declare the class “snoflake”, properties class that represents a persistent set of properties. Properties can be saved to a stream or loaded from a stream. Basically to maintain key-value pairs. Below is code for the same:

Here, we are creating a key-value pairs which will be used to connect to snowflake. User and Password are the credentials to connect to snowflake. You can get the account from URL as shown below (part between https:// and snowflakecomputing.com to be considered as account):

Similarly, you will find warehouse and role once you login to snowflake. Here like in part I, I’m not creating DB and Schema here I’m just making use of the DB and Schema that snowflake provides as default. Under the DB/ Schema we will find lot of public tables.

Next, we will connect to snowflake using DriverManager.getConnection

Using the JDBC driver to connect to Snowflake requires a connection string as shown above which is formatted like

“jdbc:snowflake://<account_name>.snowflakecomputing.com”

Next, Under DriverManager.getConnection, we will specify the JDBC driver and properties to connect to snowflake with the parameters defined. Next, we will create statement, next we will be executing a query on “CUSTOMER” table which is a public table provided for the database and Schema SNOWFLAKE_SAMPLE_DATA and TPCDS_SF100TCL respectively.

This is just a simple tutorial on how to connect to snowflake using Java.

--

--

viswanath thatha
Analytics Vidhya

Passionate Python developer with experience in automation, analytics, data science. Experienced with snowflake data warehouse, other databases