Home » n8n» How to connect hana to n8n: Docker + JDBC guide

How to connect hana to n8n?

You can connect SAP HANA to n8n by running a small JDBC helper service and calling it from n8n, or by mounting the HANA JDBC driver into a helper container. This guide shows how to connect hana to n8n with Docker, the ngdbc.jar JDBC driver, and a minimal HTTP-JDBC bridge so n8n workflows can run SQL queries.

What You Need

  • Docker and Docker Compose on your machine.
  • SAP HANA JDBC driver file ngdbc.jar (download from SAP).
  • Java JDK (openjdk) for the helper service.
  • n8n Docker image (n8nio/n8n) and basic n8n knowledge.
  • HANA host, port, username, and password.

Setup: how to connect hana to n8n

Step 1: Prepare files and driver

Create a folder and place the HANA JDBC driver in it. Replace the URL with your SAP download link.

mkdir hana-n8n
cd hana-n8n
# Example placeholder - download ngdbc.jar from SAP Support Portal
curl -L -o ngdbc.jar "https://your.sap.download/ngdbc.jar"

Step 2: Create a minimal Java HTTP-JDBC bridge

Save this file as Main.java in the same folder. The bridge reads HANA credentials from environment variables and accepts POST /query with form body sql=YOUR_SQL.

import com.sun.net.httpserver.*;
import java.io.*;
import java.net.InetSocketAddress;
import java.sql.*;
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    int port = args.length>0?Integer.parseInt(args[0]):8080;
    HttpServer server = HttpServer.create(new InetSocketAddress(port),0);
    server.createContext("/query", exchange -> {
      if(!"POST".equals(exchange.getRequestMethod())){
        exchange.sendResponseHeaders(405,-1);return;
      }
      InputStream is = exchange.getRequestBody();
      String body = new String(is.readAllBytes());
      String sql = Arrays.stream(body.split("&"))
        .filter(s->s.startsWith("sql="))
        .map(s->s.substring(4)).findFirst().orElse("");

      String host = System.getenv("HANA_HOST");
      String portEnv = System.getenv("HANA_PORT");
      String user = System.getenv("HANA_USER");
      String pass = System.getenv("HANA_PASS");
      String url = "jdbc:sap://"+host+":"+(portEnv==null?30015:Integer.parseInt(portEnv));
      StringBuilder out = new StringBuilder();
      try(Connection conn = DriverManager.getConnection(url, user, pass);
          PreparedStatement ps = conn.prepareStatement(sql);
          ResultSet rs = ps.executeQuery()){
        ResultSetMetaData m = rs.getMetaData();
        out.append("[");
        boolean firstRow=true;
        while(rs.next()){
          if(!firstRow) out.append(",");
          firstRow=false;
          out.append("{");
          for(int i=1;i<=m.getColumnCount();i++){
            out.append('"').append(m.getColumnName(i)).append('"')
               .append(":\"").append(rs.getString(i)).append("\"");
            if(i

Step 3: Build a simple Docker setup

Create a Dockerfile that compiles and runs the Java bridge. Place it beside ngdbc.jar and Main.java.

FROM openjdk:11-slim
WORKDIR /app
COPY ngdbc.jar ./
COPY Main.java ./
RUN javac -cp ngdbc.jar Main.java
EXPOSE 8080
CMD ["sh","-c","java -cp .:ngdbc.jar Main 8080"]

Create docker-compose.yml

version: '3.7'
services:
  jdbc-bridge:
    build: .
    environment:
      - HANA_HOST=hana.example.com
      - HANA_PORT=30015
      - HANA_USER=myuser
      - HANA_PASS=mypassword
    ports:
      - "8080:8080"
  n8n:
    image: n8nio/n8n
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=admin
    ports:
      - "5678:5678"
    depends_on:
      - jdbc-bridge

Start both services:

docker-compose up -d --build

Step 4: Call the bridge from an n8n workflow

In n8n, use an HTTP Request node to POST SQL to the bridge. Example POST body: sql=SELECT CURRENT_TIMESTAMP FROM DUMMY.

curl -X POST http://localhost:8080/query -d "sql=SELECT CURRENT_TIMESTAMP FROM DUMMY"

Update

To update the JDBC driver or bridge code, replace ngdbc.jar or Main.java and rebuild the bridge image.

# replace ngdbc.jar, then
docker-compose build jdbc-bridge
docker-compose up -d jdbc-bridge

Security

  • Do not store plaintext credentials in version control. Use Docker secrets or environment files with restricted permissions.
  • Limit network access to the helper service. Use firewall rules or internal networks so only n8n can reach the bridge.
  • Use parameterized queries and avoid concatenating untrusted input into SQL to prevent injection.
  • Enable TLS for n8n and the helper if exposed to untrusted networks.

Done

You now have a simple, repeatable method to connect SAP HANA to n8n using Docker and the HANA JDBC driver. The bridge accepts SQL from n8n workflows and returns JSON results.

Neil
Written by Neil

Neil is a true n8n geek who lives and breathes workflow automation. He dives deep into nodes, triggers, webhooks, custom logic, and self-hosting setups, sharing everything he learns about n8n on AutomationCompare.com. As part of a broader team of automation specialists, Neil focuses purely on mastering n8n and helping others unlock its full potential.

Keep Reading

Scroll to Top