CertSafari
    Databricks Certified Data Engineer Associate· Lessons

    Domain 2 · Lesson 7/33

    JDBC reads in notebooks with Unity Catalog connections

    Use JDBC/ODBC or REST clients in notebooks to land data into cloud storage or directly into Unity Catalog-governed tables, usually orchestrated and scheduled with Lakeflow Jobs

    15 min read
    3% of exam
    10 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Decide when a JDBC Unity Catalog connection beats query federation for reading an external database
    • Set up the driver volume, privileges and option allowlist a JDBC connection needs
    • Push filtering to the source database with the query option instead of filtering in Spark
    • Parallelise a large JDBC read with partitionColumn, lowerBound, upperBound and numPartitions
    • Keep database credentials out of notebook source and job configuration

    Key concept

    JDBC Unity Catalog connection — A governed Unity Catalog object that holds the JDBC driver, the database URL and the credentials. A notebook reads through it by name with the Spark Data Source API, and the user running the notebook never sees the credentials.

    1.When a notebook should read over JDBC

    Reading an operational database from a notebook is the do-it-yourself end of ingestion. You write the Spark read, choose the SQL, and decide where the rows land. Databricks offers two governed ways to reach the same database, and they suit different jobs. Query federation exposes the database as a foreign catalog with table-level permissions and automatic pushdown. A JDBC Unity Catalog connection gives a notebook a named connection to read through with the full Spark Data Source API. If federation supports your database, Databricks recommends federation.

    A JDBC connection is the better choice in a specific set of cases:

    • the database is not supported by query federation
    • you need a particular JDBC driver
    • you need to write back to the source, which federation cannot do
    • you want control over parallelism through Spark options
    • you want to push a hand-written SQL statement to the source with the query option

    The trade-off is governance granularity. Federation can grant access table by table. A JDBC connection is governed only as a whole: a user who may use the connection can reach whatever its credentials can reach. A JDBC connection is also not a copy of the data. Rows you read sit in Spark memory only for the life of the job, so a notebook that ingests must write them to a Unity Catalog table itself. Databricks recommends addressing those tables by name rather than by storage path.

    Three ways to reach an external database, and what each leaves you with
    FeatureSpark Data Source APILakehouse FederationLakeflow Connect
    Primary use caseComplex ETL, custom Spark logic, pass-through queriesAd-hoc queries, BI reportingHigh-scale, automated ingestion
    Data movementLoaded into Spark memory (ephemeral)Loaded into Spark memory (ephemeral)Copied to Delta Lake (persistent)
    Query executionManual pushdown using the native query optionAutomatic pushdown of Spark and SQL filters, joins, and aggregationsNot applicable (full table replication)
    GovernanceUnity Catalog connection (JDBC) or secret scopesUnity Catalog (federated catalog)Unity Catalog (managed pipeline)

    The landing target decides how the rows are governed afterwards. Tabular results belong in a Unity Catalog table addressed by its three-part name, <catalog>.<schema>.<table>; Databricks recommends reading and writing tables by name rather than by cloud storage path. Raw or non-tabular output, such as JSON or CSV extracts, belongs in a volume under /Volumes/<catalog>/<schema>/<volume>, which Databricks recommends for all access to non-tabular data in cloud object storage. Underneath both sits an external location, a storage path paired with a storage credential. Grant users the table or volume, not the bucket: direct storage access bypasses Unity Catalog permissions, auditing and lineage.

    Checkpoint 1 of 9· Check yourself

    A notebook reads orders from a PostgreSQL database, which query federation supports. It enriches the rows in Spark and must then write a status value back to the same PostgreSQL table. Which way of reaching the database fits this job?

    Sources1234

    2.Creating the connection: driver, privileges and allowlist

    The connection installs its driver from a Unity Catalog volume. You upload the JDBC driver JAR to a volume, and the connection loads it into an isolated sandbox on the compute. That arrangement creates three permission requirements. The creator needs the CREATE CONNECTION privilege on the metastore. The creator also needs CREATE or MANAGE access to the volume. Every user who queries the connection needs read access to that volume, which is granted with GRANT READ VOLUME ... TO the querying group. A user who has the connection but not the volume cannot load the driver.

    Compute matters too. The connection works on serverless, and on Databricks Runtime 17.3 LTS or above in standard or dedicated access mode. It is generally available from Runtime 19. This is the route for serverless and standard clusters: they do not accept custom third-party Spark JARs, so a driver installed on a cluster is not an option there.

    You create the connection in Catalog Explorer (Connect, then Connections, then connection type JDBC) or with CREATE CONNECTION in SQL. Only the URL and credentials are required. The externalOptionsAllowList setting controls which Spark options a querying user may add at read time. Its default is dbtable,query,partitionColumn,lowerBound,upperBound,numPartitions. Setting it to an empty string locks users to the options defined on the connection, and users can never override url or host. For SQL Server, where the URL does not pin the database, add database to the allowlist so that readers can choose it.

    Reading through a JDBC Unity Catalog connection by name: no URL, user or password in the notebookpython
    df = (spark.read
      .format("jdbc")
      .option("databricks.connection", "<connection-name>")
      .option("query", "SELECT * FROM external_table")
      .load())

    Checkpoint 2 of 9· Fill the gap

    This notebook reads through a JDBC Unity Catalog connection by name, so it has no URL, user or password in it. Which option key completes the read?

    df = (spark.read
      .format("jdbc")
      .option(" ? ", "<connection-name>")
      .option("query", "SELECT * FROM external_table")
      .load())

    Checkpoint 3 of 9· Check yourself

    An analyst has been granted use of a JDBC Unity Catalog connection. When their serverless notebook reads through it, the JDBC driver fails to load. What fixes this?

    Sources15

    3.Pushing filters to the source with the query option

    With the Spark Data Source API, pushdown is your job. Federation rewrites Spark filters, joins and aggregations into source SQL automatically. A JDBC read is described as manual pushdown, done through the native query option. A read that loads a whole table and then calls .filter() and .select() in Spark gives no such guarantee; the one placement that is certain to run at the source is the SQL inside query.

    The query option carries a SQL statement that runs entirely on the external database. Spark receives only that statement's result and does not push any transformation into the string. If a notebook needs four columns of yesterday's rows from a 50-column, 80-million-row table, write that projection and that WHERE clause into the SQL the source runs. The database then does the filtering, and only the narrow result travels to Databricks.

    A bundled-connector read whose SELECT and WHERE run on SQL Server, with credentials pulled from a secret scopepython
    df = (spark.read
      .format("sqlserver")
      .option("host", "<your-sql-server-instance>.database.windows.net")
      .option("user", dbutils.secrets.get(scope="<scope>", key="<user>"))
      .option("password", dbutils.secrets.get(scope="<scope>", key="<password>"))
      .option("database", "<database-name>")
      .option("query", "SELECT id, name FROM users WHERE active = 1")
      .load())

    Checkpoint 4 of 9· Check yourself

    A notebook reads one 50-column table over JDBC and needs only four columns of yesterday's rows. Network transfer is the bottleneck. Which change makes sure the source database does the narrowing?

    Checkpoint 5 of 9· Exam question

    A notebook currently reads an entire 50-column, 80 million-row transactions table over JDBC into a DataFrame, then immediately filters it in Spark to keep only rows from the last 24 hours and only 4 of the columns before writing the result to a Unity Catalog table. Networking between Databricks and the source database is the bottleneck. Which change reduces the amount of data pulled over the JDBC connection itself?

    Sources5

    4.Splitting a large read into parallel range queries

    A JDBC read is serial unless you tell Spark how to split it. The split is given by a numeric or orderable column plus its range. Spark divides the range from lowerBound to upperBound into numPartitions slices and issues one range query per slice over separate connections. An evenly distributed, monotonically increasing key such as order_id is the ideal column, because every slice gets a similar share of rows. A skewed column leaves one task with most of the work.

    The options that turn one JDBC scan into parallel range queries
    OptionMeaningNote
    partitionColumn (column in the jdbc method)The column used to split the readRequires lowerBound, upperBound and numPartitions
    lowerBoundMinimum value of the column for partitioningRequired when the column is specified
    upperBoundMaximum value of the column for partitioningRequired when the column is specified
    numPartitionsNumber of partitions, and therefore parallel queriesToo many on a large cluster can crash the source database
    predicatesA list of WHERE expressions, one per partitionIgnored if a column is specified

    Choosing numPartitions sets how hard you hit the source. Every partition is a concurrent session on a database that is usually also serving production traffic. Raising the number shortens the read until the database becomes the bottleneck, and past that point it can take the database down. Start small and raise it only while the source stays healthy; values in the hundreds are too high. These four option names are in the connection's default allowlist, so a notebook reading through a JDBC Unity Catalog connection can set them without an administrator changing anything.

    Partitioning and the query option do not mix. partitionColumn cannot be used with query, so a partitioned read names its source with dbtable instead, and all four partition options must be set together. A read that needs a hand-written SQL statement runs as a single query; a read that needs parallel range queries gives up the query option.

    Checkpoint 6 of 9· Match them up

    Match each JDBC read option to the role it plays when Spark splits one large table read into parallel queries.

    Tap a term, then the definition that fits it.

    Checkpoint 7 of 9· Exam question

    A data engineer runs a nightly notebook task in a Lakeflow Job that reads a 200 million-row orders table from an on-premises PostgreSQL database using spark.read.format("jdbc"). Without any partitioning options set, the job opens a single connection and the read consistently takes over three hours before timing out. The order_id column is a monotonically increasing integer primary key with values evenly distributed across the full range. Which change is most likely to reduce the read time while keeping the load on the source database controlled?

    Sources617

    5.Keeping credentials out of notebooks and jobs

    A database password written as a literal in an .option() call is readable by anyone who can open the notebook or the job that runs it. There are two supported places for credentials, and both keep the value out of the source code.

    The first is the connection itself. A JDBC Unity Catalog connection stores the credentials, and querying users never see them. Do not embed credentials in the connection URL, because logs or error messages can expose them. Use the connection's dedicated credential fields instead. The second, for reads that do not go through a connection, is a secret scope. The notebook calls dbutils.secrets.get(scope=..., key=...) at run time, as in the SQL Server example above. Databricks makes an effort to redact secret values displayed in notebooks.

    Two common fixes do not work. Base64 encoding is not protection, since anyone can decode it. Locking down the folder still leaves the plaintext in the code. A job parameter is not a secret store either. Parameters are plain configuration values that the job hands to its tasks by key; a default value is not a security control, and anyone with CAN MANAGE RUN permission or higher can override it for a manual run. The job definition itself can be opened as JSON or YAML, so a password placed there is readable by whoever can view the job.

    Checkpoint 8 of 9· Check yourself

    Your team runs a nightly Lakeflow job whose notebook has a SQL Server password written into an .option() call. You are moving the read onto a JDBC Unity Catalog connection so that people who can view the notebook or the job never see the password. Where should the password go?

    Checkpoint 9 of 9· Exam question

    During a code review, a data engineer notices that a coworker's notebook task builds a JDBC connection string that includes the literal database username and password directly in the .option("password", ...) call, and this notebook is scheduled to run daily as part of a Lakeflow Job that several other engineers can view. What is the recommended way to fix this before the job is promoted to production?

    Sources18910

    Sources

    (10)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “If your database is supported, Databricks recommends using query federation instead of a JDBC connection.”
      ↩︎ When a notebook should read over JDBC
      “You need to write to the data source using Spark (query federation doesn't support writes).”
      ↩︎ When a notebook should read over JDBC
      “JDBC Unity Catalog connection provides governance only at the connection level.”
      ↩︎ When a notebook should read over JDBC
      “The JDBC connection reads and installs the JDBC driver JAR from a Unity Catalog volume.”
      ↩︎ Creating the connection: driver, privileges and allowlist
      “To create a connection, you must have the CREATE CONNECTION privilege on the metastore attached to the workspace.”
      ↩︎ Creating the connection: driver, privileges and allowlist
      “Volume access by the user querying the connection.”
      ↩︎ Creating the connection: driver, privileges and allowlist
      “Databricks compute must use serverless, or Databricks Runtime 17.3 LTS or above on standard mode or dedicated access mode.”
      ↩︎ Creating the connection: driver, privileges and allowlist
      “Set it to an empty string to restrict users to only the options defined in the connection. Users can never specify url or host.”
      ↩︎ Creating the connection: driver, privileges and allowlist
      “If not specified, the default is 'dbtable,query,partitionColumn,lowerBound,upperBound,numPartitions'.”
      ↩︎ Splitting a large read into parallel range queries
      “Connection credentials are hidden from the querying user.”
      ↩︎ Keeping credentials out of notebooks and jobs
      “Don't embed credentials in the URL, because logs or errors can expose them.”
      ↩︎ Keeping credentials out of notebooks and jobs
      “The JDBC connection is a securable object in Unity Catalog that specifies the JDBC driver, the URL path, and credentials”
      ↩︎ Key concept
      “Grant read access on the volume to the users who query the connection”
      ↩︎ Checkpoint
      “Don't embed credentials in the URL, because logs or errors can expose them. Use the dedicated credential options for your chosen authentication method.”
      ↩︎ Checkpoint
    2. 2.
      “Databricks recommends that users read and write all Unity Catalog tables using table names and access data in volumes using /Volumes paths.”
      ↩︎ When a notebook should read over JDBC
      “The only identity that should have access to data managed by Unity Catalog is the identity used by Unity Catalog.”
      ↩︎ When a notebook should read over JDBC
    3. 3.
      “Databricks recommends using volumes for managing all access to non-tabular data in cloud object storage”
      ↩︎ When a notebook should read over JDBC
    4. 4.
      “identifying the table using the format <catalog-name>.<schema-name>.<table-name>”
      ↩︎ When a notebook should read over JDBC
    5. 5.
      “Custom third-party Spark JARs are not supported on Databricks SQL, serverless, or standard access mode compute.”
      ↩︎ Creating the connection: driver, privileges and allowlist
      “When using the query option, the specified SQL statement runs entirely on the external data source.”
      ↩︎ Pushing filters to the source with the query option
      “Spark fetches the results without performing transformation pushdown on the query string.”
      ↩︎ Pushing filters to the source with the query option
      “Using the query option ensures that filter and join logic executes on the source database before data reaches Spark.”
      ↩︎ Pushing filters to the source with the query option
      “Manual pushdown using the native query option”
      ↩︎ Exam trap 1
    6. 6.
      “Partitions of the table are retrieved in parallel if either column or predicates is specified.”
      ↩︎ Splitting a large read into parallel range queries
      “Avoid creating too many partitions in parallel on a large cluster, as this can crash external database systems.”
      ↩︎ Splitting a large read into parallel range queries
      “Avoid creating too many partitions in parallel on a large cluster, as this can crash external database systems.”
      ↩︎ Exam trap 2
      “Partitions of the table are retrieved in parallel if either column or predicates is specified. If both column and predicates are specified, column takes precedence.”
      ↩︎ Checkpoint
    7. 8.
      “The secrets utility module contains commands to store and access sensitive credential information without making them visible in notebooks.”
      ↩︎ Keeping credentials out of notebooks and jobs
      “The secrets utility module contains commands to store and access sensitive credential information without making them visible in notebooks.”
      ↩︎ Exam trap 3
    8. 9.
      “You can also view the JSON definitions for use with REST API get, create, and reset endpoints.”
      ↩︎ Keeping credentials out of notebooks and jobs
      “To view a job as YAML, click the kebab menu to the left of Run now for the job”
      ↩︎ Keeping credentials out of notebooks and jobs
    9. 10.
      “A default parameter value is not a security control.”
      ↩︎ Keeping credentials out of notebooks and jobs

    Continue to part 2 of 2

    REST API ingestion from a scheduled notebook

    Spotted a mistake, or was something unclear? Tell us.