This Java application demonstrates how to connect to Databricks using the Databricks Connect API. It provides multiple ways to configure and establish connections to Databricks clusters, along with examples of Spark operations.
- Access to a Databricks workspace
- A Databricks cluster or serverless compute
- Databricks personal access token
git clone <your-repo-url>
cd javadbconnect
mvn clean compileYou have several options to configure the connection:
Update the databricks.properties file with your actual values:
databricks.host=https://your-workspace.cloud.databricks.com
databricks.token=your-personal-access-token
databricks.cluster.id=your-cluster-id-
Workspace Hostname: Go to your Databricks workspace URL and copy the hostname (e.g.,
adb-1234567890123456.7.azuredatabricks.net) -
Personal Access Token:
- Go to User Settings → Developer → Access Tokens
- Click "Generate New Token"
- Copy the generated token
-
Cluster ID (for classic compute):
- Go to your cluster in the Databricks workspace
- Copy the cluster ID from the URL (e.g.,
1234-567890-abc123)
# Compile the project
mvn clean compile
# Run UserDataExample
java --add-opens=java.base/java.nio=ALL-UNNAMED \
--add-opens=java.base/sun.misc=ALL-UNNAMED \
--add-exports=java.base/sun.security.action=ALL-UNNAMED \
-Dio.netty.tryReflectionSetAccessible=true \
-cp target/classes:$(mvn dependency:build-classpath -q -Dmdep.outputFile=/dev/stdout) \
com.example.databricks.UserDataExample
# Run BatchUserStreamingExample (batch processing 10M rows generation)
java --add-opens=java.base/java.nio=ALL-UNNAMED \
--add-opens=java.base/sun.misc=ALL-UNNAMED \
--add-exports=java.base/sun.security.action=ALL-UNNAMED \
-Dio.netty.tryReflectionSetAccessible=true \
-cp target/classes:$(mvn dependency:build-classpath -q -Dmdep.outputFile=/dev/stdout) \
com.example.databricks.BatchUserStreamingExampleThis project is provided as an example and is not officially supported by Databricks.
