Connect Java and desktop tools with JDBC and ODBC
JDBC serves Java applications. ODBC serves compatible desktop and reporting tools.
Understand the idea
Add the official Snowflake JDBC dependency using a version compatible with your Java runtime and the current driver documentation. The JDBC URL includes the Snowflake server host. Pass user, authentication and context settings through connection properties appropriate for your chosen driver version.
| Concept | What it means |
|---|---|
| JDBC | Install the driver → connect → execute a statement → read ResultSet → close resources. |
| ODBC | Install the matching driver → configure DSN → select it in the calling tool → query. |
| DSN | A named connection configuration visible to a particular user or system. |
| Authentication | Must be supported by the driver version, application and account. |
A concrete example
A desktop DSN may be unavailable to a scheduled service running under another user. Inspect that service’s environment.
Remember: Check caller identity, driver compatibility and connection settings before changing permissions.
Explain it step by step · full theory
JDBC provides the Java database interface
A Java application loads the Snowflake JDBC driver and opens a connection. It creates a statement, executes SQL, reads rows from the result set and closes the resources. The driver handles the communication with Snowflake.
Add the official Snowflake JDBC dependency using a version compatible with your Java runtime and the current driver documentation. The JDBC URL includes the Snowflake server host. Pass user, authentication and context settings through connection properties appropriate for your chosen driver version.
For a first exercise, use a read-only VALUES query. Confirm that the application retrieves one numeric value before adding business queries. Production code should bind input parameters using a prepared statement rather than assembling untrusted values into SQL strings.
Read the Java resource lifecycle
The example below is a method-body fragment for a project with the Snowflake JDBC dependency. It expects a trusted SNOWFLAKE_JDBC_URL and a Properties object populated with the approved authentication and context settings.
DriverManager.getConnection opens the session, createStatement prepares the client statement object, executeQuery returns a ResultSet, and next moves to the first result row. getInt(1) reads the first column. The try-with-resources block closes the result, statement and connection when the work exits.
ODBC uses the driver manager and a data source configuration
ODBC is a standard interface supported by many desktop and BI applications. Install the Snowflake ODBC driver matching your operating system and application architecture, then configure a data source name, or DSN, through the platform’s driver manager or configuration files.
Enter the Snowflake server, database/schema, role and warehouse and choose an authentication method supported by both the driver and the calling application. Test the DSN, then select it inside your reporting tool and run a small read query.
A DSN saved for your desktop user may be invisible to a server process running as another identity. Driver version and bitness also matter. Current ODBC releases may change parameter names, and browser authentication support varies by application. Diagnose the actual caller’s environment before changing account permissions.
Words used in this lesson
- JDBC
- Java Database Connectivity.
- ODBC
- Open Database Connectivity.
- DSN
- A named data source configuration used by ODBC applications.
- ResultSet
- The Java object used to read query results.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Connect Java and desktop tools with JDBC and ODBC
JDBC
A Java application calls the database driver.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- JDBC
A Java application calls the database driver.
- ODBC
A tool finds a configured driver and data source.
- Close
Inspect results and release client resources.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Optional connectivity path. You do not need to write Java to learn Snowflake. Read this comparison first; manual JDBC/ODBC practice requires a compatible client, its driver and authorized connection configuration.
JDBC query lifecycle inside a configured Java project
// Required imports: java.sql.* and java.util.Properties
// authProperties is configured by your approved authentication setup.
String url = System.getenv("SNOWFLAKE_JDBC_URL");
try (Connection connection = DriverManager.getConnection(url, authProperties);
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("SELECT 101 AS ORDER_ID")) {
if (result.next()) {
System.out.println(result.getInt(1));
}
}What to expect and why
This fragment prints 101 when authentication and execution succeed. It deliberately requires the project’s authentication Properties object and a valid JDBC URL. Use the linked driver setup for your chosen authentication flow.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Explain the lifecycle of one JDBC query and the configuration of an ODBC caller.
Compare your reasoning
JDBC opens a connection, executes a statement, fetches records and closes resources. ODBC requires a compatible application, installed driver and accessible DSN or equivalent connection settings.