{"id":3874,"library":"apache-airflow-providers-jdbc","title":"Apache Airflow JDBC Provider","description":"The Apache Airflow JDBC Provider extends Airflow's functionality by enabling interaction with JDBC-compatible databases through specialized hooks and operators. It is part of the larger Apache Airflow ecosystem, with frequent releases that align with new Airflow versions and community contributions. The current version is 5.4.2.","status":"active","version":"5.4.2","language":"en","source_language":"en","source_url":"https://github.com/apache/airflow/tree/main/airflow/providers/jdbc","tags":["airflow","jdbc","database","provider","sql","etl"],"install":[{"cmd":"pip install apache-airflow-providers-jdbc","lang":"bash","label":"Install only JDBC provider"},{"cmd":"pip install apache-airflow[jdbc]","lang":"bash","label":"Install Airflow with JDBC extra (includes jaydebeapi)"}],"dependencies":[{"reason":"Core Apache Airflow installation is required.","package":"apache-airflow","version":">=2.11.0"},{"reason":"Python DB-API 2.0 adapter for JDBC.","package":"jaydebeapi","version":">=1.1.1"},{"reason":"Cross-provider dependency for compatibility.","package":"apache-airflow-providers-common-compat","version":">=1.14.0"},{"reason":"Common SQL functionality for providers, which includes SQLExecuteQueryOperator.","package":"apache-airflow-providers-common-sql","version":">=1.32.0"},{"reason":"Required to run JDBC drivers.","package":"JVM (Java Virtual Machine)","optional":false},{"reason":"Must be set to the path of your JVM installation.","package":"JAVA_HOME environment variable","optional":false},{"reason":"Required to connect to the target database.","package":"JDBC driver JAR file for your specific database","optional":false}],"imports":[{"symbol":"JdbcHook","correct":"from airflow.providers.jdbc.hooks.jdbc import JdbcHook"},{"note":"The `JdbcOperator` has been deprecated and removed in recent versions of the provider. Use `SQLExecuteQueryOperator` from `common.sql` instead.","wrong":"from airflow.providers.jdbc.operators.jdbc import JdbcOperator","symbol":"SQLExecuteQueryOperator","correct":"from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator"}],"quickstart":{"code":"from __future__ import annotations\n\nimport os\n\nfrom airflow.models.dag import DAG\nfrom airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator\nfrom airflow.utils.dates import days_ago\n\nwith DAG(\n    dag_id='example_jdbc_sql_query',\n    start_date=days_ago(1),\n    schedule_interval=None,\n    catchup=False,\n    tags=['jdbc', 'example', 'sql'],\n) as dag:\n    # To run this DAG, ensure you have:\n    # 1. A JVM installed and JAVA_HOME environment variable set.\n    # 2. The specific JDBC driver JAR file for your database available (e.g., /path/to/your/driver.jar).\n    # 3. An Airflow JDBC connection configured with:\n    #    - Conn Id: 'my_jdbc_connection'\n    #    - Conn Type: 'JDBC Connection'\n    #    - Host: 'jdbc:<vendor>://<host>:<port>/<database>' (the full JDBC URL)\n    #    - Login: '<username>'\n    #    - Password: '<password>'\n    #    - Extra: {'driver_path': '/path/to/your/driver.jar', 'driver_class': 'com.vendor.DriverClass'}\n    #    Refer to official documentation for specific database driver_class and driver_path values.\n\n    # Example 1: Execute a SELECT query\n    execute_select_query = SQLExecuteQueryOperator(\n        task_id='execute_select_query',\n        conn_id='my_jdbc_connection',\n        sql=\"SELECT * FROM example_table WHERE status = 'active';\",\n        handler=lambda cursor: [row for row in cursor], # Example handler to fetch results\n    )\n\n    # Example 2: Execute an INSERT statement\n    execute_insert_statement = SQLExecuteQueryOperator(\n        task_id='execute_insert_statement',\n        conn_id='my_jdbc_connection',\n        sql=\"INSERT INTO log_table (event_time, message) VALUES (NOW(), 'Data processed successfully');\",\n        autocommit=True,\n    )\n\n    execute_select_query >> execute_insert_statement\n","lang":"python","description":"This quickstart demonstrates how to use the `SQLExecuteQueryOperator` to interact with a JDBC-compatible database. It requires a pre-configured Airflow connection, a JVM, the `JAVA_HOME` environment variable, and the specific JDBC driver JAR file for your database. The `SQLExecuteQueryOperator` can execute single or multiple SQL queries. For fetching results, a `handler` callable can be provided. Make sure to replace placeholder values for the JDBC connection details and SQL queries with your actual data."},"warnings":[{"fix":"Replace `JdbcOperator` imports and usage with `SQLExecuteQueryOperator`. The parameters `sql`, `conn_id`, and `autocommit` are largely compatible.","message":"The `JdbcOperator` has been deprecated and subsequently removed from the `apache-airflow-providers-jdbc` package. Users should migrate to `airflow.providers.common.sql.operators.sql.SQLExecuteQueryOperator` for executing SQL commands via JDBC.","severity":"breaking","affected_versions":"Provider versions 5.x.x and later. Deprecated in earlier 4.x versions, removed in 5.x."},{"fix":"Upgrade your Apache Airflow installation to at least the minimum required version for the `apache-airflow-providers-jdbc` package you are using. If upgrading from Airflow < 2.1.0, manually run `airflow upgrade db` after the Airflow core upgrade.","message":"Minimum Apache Airflow version requirements have increased across provider versions. Ensure your Airflow installation meets the minimum version for the installed provider version to avoid issues related to API changes and decorator removals (e.g., `apply_default`).","severity":"breaking","affected_versions":"Provider versions >= 2.0.0 require Airflow >= 2.1.0; Provider versions >= 3.0.0 require Airflow >= 2.2.0; Provider versions >= 4.2.0 require Airflow >= 2.6.0; Provider version 5.4.2 requires Airflow >= 2.11.0."},{"fix":"Install a JVM, set the `JAVA_HOME` environment variable to its installation path, and download the appropriate JDBC driver `.jar` file. Ensure `jaydebeapi` is installed in your Airflow environment.","message":"Connecting to JDBC databases requires a properly configured Java environment, including a Java Virtual Machine (JVM), the `JAVA_HOME` environment variable set, and the specific JDBC driver `.jar` file for your database.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If safe to do so in your environment, set `allow_driver_class_in_extra = True` and/or `allow_driver_path_in_extra = True` in your `airflow.cfg` or via environment variables (e.g., `AIRFLOW__PROVIDERS_JDBC__ALLOW_DRIVER_CLASS_IN_EXTRA=True`). Exercise caution as enabling these allows users to specify custom drivers and paths via the UI, which could have security implications if not properly managed.","message":"For security reasons, `allow_driver_class_in_extra` and `allow_driver_path_in_extra` configuration options in `airflow.cfg` (under `[providers.jdbc]`) are `False` by default. If you need to specify `driver_class` or `driver_path` in the Airflow Connection's 'Extra' field, these options must be explicitly set to `True`.","severity":"gotcha","affected_versions":"Provider versions >= 4.0.0"},{"fix":"To fetch results, use `JdbcHook.get_pandas_df()` within a `PythonOperator` or define a `handler` function for the `SQLExecuteQueryOperator` to process the `cursor` object.","message":"The `JdbcOperator` (when it was in use) and `SQLExecuteQueryOperator` primarily execute SQL statements and do not automatically return query results to logs or XComs. To fetch results from a `SELECT` query, you typically need to use the `JdbcHook` directly or provide a `handler` callable to the operator.","severity":"gotcha","affected_versions":"All versions for `JdbcHook`, `SQLExecuteQueryOperator`"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}