Skip to main content

Configure a connection to Databricks using the Databricks JDBC Driver

note

This article applies to the Databricks JDBC Simba driver. For the Databricks-developed JDBC driver, see Databricks JDBC Driver (OSS).

This article describes how to configure a connection to Databricks using the Databricks JDBC Driver.

To configure a Databricks connection for the Databricks JDBC Driver, you must combine your compute resource settings, any driver capability settings, and authentication settings, into a JDBC connection URL or programmatic collection of JDBC connection properties, or both.

JDBC connection URLs use the following format:

jdbc:databricks://<server-hostname>:443;httpPath=<http-path>[;<setting1>=<value1>;<setting2>=<value2>;<settingN>=<valueN>]

JDBC connection properties can be set in Java such as the following example:

Java
package org.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Properties;

public class Main {
public static void main(String[] args) throws Exception {
Class.forName("com.databricks.client.jdbc.Driver");
String url = "jdbc:databricks://" + System.getenv("DATABRICKS_SERVER_HOSTNAME") + ":443";
Properties p = new java.util.Properties();
p.put("httpPath", System.getenv("DATABRICKS_HTTP_PATH"));
p.put("<setting1>", "<value1");
p.put("<setting2>", "<value2");
p.put("<settingN>", "<valueN");
try (Connection conn = DriverManager.getConnection(url, p)) {
Statement stmt = conn.createStatement();
try (ResultSet rs = stmt.executeQuery("<query>")) {
ResultSetMetaData md = rs.getMetaData();
String[] columns = new String[md.getColumnCount()];
for (int i = 0; i < columns.length; i++) {
columns[i] = md.getColumnName(i + 1);
}
while (rs.next()) {
System.out.print("Row " + rs.getRow() + "=[");
for (int i = 0; i < columns.length; i++) {
if (i != 0) {
System.out.print(", ");
}
System.out.print(columns[i] + "='" + rs.getObject(i + 1) + "'");
}
System.out.println(")]");
}
}
}
System.exit(0);
}
}
  • Set the DATABRICKS_SERVER_HOSTNAME and DATABRICKS_HTTP_PATH environment values to the target Databricks compute resource’s Server Hostname and HTTP Path values, respectively. To get these values, see Compute settings for the Databricks JDBC Driver. To set environment variables, see your operating system’s documentation.
  • Replace <setting> and <value> as needed for properties of your chosen authentication type.
  • You can also add special or advanced driver capability settings, typically as additional <setting> and <value> pairs.
  • For this example, replace <query> with a SQL SELECT query string.

Whether you use a connection URL or a collection of connection properties will depend on the requirements of your target app, tool, client, SDK, or API.