Skip to content

Snowflake: Java (snowflake-jdbc)

# host / account URL
myorg-myaccount.snowflakecomputing.com
warehouse.internal (MachWarehouse Snowflake REST endpoint, HTTPS 443)
# account
myorg-myaccount
the MachWarehouse account name (any label; kept for drivers that require it)
# user / password, role, warehouse, database, schema
Snowflake values
MachWarehouse values (warehouse = compute pool)
# SNOWFLAKE_JDBC_URL
Before
After
jdbc:snowflake://myorg-myaccount.snowflakecomputing.com/?db=DEMO&schema=PUBLIC&warehouse=BI
jdbc:snowflake://warehouse.internal:443/?account=demo&db=DEMO&schema=PUBLIC&warehouse=BI

The same URL works in DBeaver, Tableau and every JDBC tool with the Snowflake driver.

Terminal window
mvn -q compile exec:java

Library: net.snowflake:snowflake-jdbc 4.4.0, Java 25 LTS.

The program as it is kept and tested in the Mach Database Warehouse repository; highlighted lines read the connection setting.

src/main/java/example/Main.java
package example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
/** Prints revenue per country with snowflake-jdbc. Plain JDBC code; the host is in the URL. */
public final class Main {
private Main() {}
public static void main(String[] args) throws Exception {
// Before: jdbc:snowflake://myorg-myaccount.snowflakecomputing.com/?db=DEMO&schema=PUBLIC&warehouse=BI
// After: jdbc:snowflake://warehouse.internal:443/?account=demo&db=DEMO&schema=PUBLIC&warehouse=BI
String url = System.getenv("SNOWFLAKE_JDBC_URL");
Properties props = new Properties();
props.setProperty("user", System.getenv("SNOWFLAKE_USER"));
props.setProperty("password", System.getenv("SNOWFLAKE_PASSWORD"));
props.setProperty("role", System.getenv().getOrDefault("SNOWFLAKE_ROLE", "ANALYST"));
try (Connection conn = DriverManager.getConnection(url, props);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(
"SELECT country, COUNT(*) AS events, SUM(revenue) AS revenue FROM events GROUP BY country ORDER BY revenue DESC")) {
while (rs.next()) {
System.out.printf("%s\t%d\t%s%n", rs.getString(1), rs.getLong(2), rs.getBigDecimal(3));
}
}
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example.machwarehouse</groupId>
<artifactId>snowflake-jdbc-example</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<exec.mainClass>example.Main</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
</project>