Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Note
This page applies to Databricks JDBC driver versions lower than 3. For Databricks JDBC driver version 3 and above, see Databricks JDBC Driver.
This page describes how to configure a connection to Azure Databricks using the Databricks JDBC Driver.
To configure a connection, combine the following settings into a JDBC connection URL or a programmatic collection of connection properties:
Connection URL format
JDBC connection URLs use the following format:
jdbc:databricks://<server-hostname>:443;httpPath=<http-path>[;<setting1>=<value1>;<setting2>=<value2>;<settingN>=<valueN>]
- For
<server-hostname>and<http-path>values, see Compute settings for the Databricks JDBC Driver (Simba). - Replace
<setting>=<value>with your connection properties.
Java example
The following example shows how to configure connection properties in 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_HOSTNAMEandDATABRICKS_HTTP_PATHenvironment variables to your compute resource's Server Hostname and HTTP Path values. See Compute settings for the Databricks JDBC Driver (Simba) and your operating system's documentation. - Replace
<setting>and<value>with your authentication settings and any driver capability settings. - Replace
<query>with a SQLSELECTquery string.
Choose a connection URL or connection properties based on the requirements of your application, tool, or SDK.