Thursday, 27 February 2025

How to Get and Configure the Flink JDBC Driver for DBeaver

 

How to Get and Configure the Flink JDBC Driver for DBeaver

Where to Get the Flink JDBC Driver

Since Flink does not provide an official pre-built JDBC driver, you need to obtain the Flink SQL Gateway JDBC Driver manually. Here are different ways to get it:


Option 1: Download from Maven Repository (Recommended)

You can download the Flink SQL Gateway JDBC driver from the official Apache Flink Maven repository.

Steps to Download from Maven

  1. Visit the Apache Flink Maven Repository
  2. Search for flink-sql-gateway-driver
  3. Download the latest jar file (e.g., flink-sql-gateway-driver-1.17.0.jar)
  4. Place the downloaded .jar file in a location where DBeaver can access it.

Option 2: Extract from a Flink Distribution (If Available)

If you already installed Flink manually, you can check if the driver is included.

Steps to Locate the Driver in Your Flink Installation

  1. If you have a Flink installation on your local system, check:
    ls $FLINK_HOME/lib/
    
  2. Look for a file like:
    flink-sql-gateway-driver-*.jar
    
  3. If found, copy it to your local system for DBeaver.

Option 3: Build the Driver from Source (Advanced Users)

If the pre-built JAR is not available, you can build it manually.

Steps to Build from Source

  1. Clone the Flink repository:
    git clone https://github.com/apache/flink.git
    cd flink
    
  2. Build the driver:
    mvn clean package -DskipTests -pl flink-table/flink-sql-gateway -am
    
  3. After the build completes, the JAR will be located in:
    flink-table/flink-sql-gateway/target/flink-sql-gateway-driver-*.jar
    
  4. Copy the JAR to your local system.

Adding the JDBC Driver to DBeaver

Once you have the JAR file, follow these steps:

  1. Open DBeaver
  2. Go to DatabaseDriver Manager
  3. Click New → Enter:
    • Driver Name: Flink JDBC
    • Class Name: org.apache.flink.table.client.gateway.JdbcDriver
    • URL Template: jdbc:flink://<jobmanager-host>:8083
  4. Click Add File, then select the downloaded JDBC JAR file
  5. Click OK to save

Now, when you create a new connection in DBeaver, you should be able to select Flink JDBC and connect.


Step-by-Step Guide to Access Flink SQL via JDBC in DBeaver

Step 1: Ensure Flink SQL Gateway is Running

Since you're manually starting the SQL Gateway inside the JobManager, verify it's running:

podman exec -it flink-jobmanager ps aux | grep sql-gateway

If it’s not running, start it inside the JobManager container:

podman exec -it flink-jobmanager /opt/flink/bin/sql-gateway.sh start

Check logs to confirm it started successfully:

podman logs flink-jobmanager | grep "Started SQL Gateway"

By default, the Flink SQL Gateway listens on port 8083.


Step 2: Expose Port 8083 (If Not Already Exposed)

Since your SQL Gateway runs inside the JobManager, ensure port 8083 is exposed for external access:

  1. Check running ports:

    podman port flink-jobmanager
    

    If 8083 is not listed, restart the container with port mapping:

    podman stop flink-jobmanager
    podman rm flink-jobmanager
    podman run -d --name flink-jobmanager -p 8081:8081 -p 8083:8083 flink:latest jobmanager
    
  2. Verify port accessibility from your machine:

    curl http://<jobmanager-host>:8083/v1/info
    

    Replace <jobmanager-host> with the actual hostname or IP.


Step 3: Create a New Connection in DBeaver

  1. Open DBeaver → Click New Database Connection
  2. Choose Flink JDBC (the one you created above)
  3. Enter:
    • URL: jdbc:flink://<jobmanager-host>:8083
    • Username: (leave empty)
    • Password: (leave empty)
  4. Click Test Connection
  5. If successful, click Finish

Step 4: Execute Flink SQL Queries in DBeaver

Now, you can execute SQL queries in DBeaver’s SQL Editor, like:

SHOW TABLES;
SELECT * FROM my_kafka_table LIMIT 10;

Troubleshooting

If you get a driver error:

  1. Check SQL Gateway logs
    podman logs flink-jobmanager | grep "SQL Gateway"
    
  2. Ensure JDBC driver is added in DBeaver
  3. Verify Flink SQL Gateway is reachable
    curl http://<jobmanager-host>:8083/v1/info
    
  4. Restart SQL Gateway if needed
    podman exec -it flink-jobmanager /opt/flink/bin/sql-gateway.sh stop
    podman exec -it flink-jobmanager /opt/flink/bin/sql-gateway.sh start
    

Now your Flink SQL Gateway should be accessible via JDBC in DBeaver.