#1
This guide shows how to integrate SAP HANA Express, Apache Kafka, and Spring Boot to stream and process real-time data.

1. Create a Table in SAP HANA

CREATE COLUMN TABLE ORDERS (
    ID INTEGER PRIMARY KEY,
    PRODUCT NVARCHAR(100),
    QUANTITY INT,
    CREATED_AT TIMESTAMP
);

2. Add Dependencies

In pom.xml:
<dependency>
  <groupId>org.springframework.kafka</groupId>
  <artifactId>spring-kafka</artifactId>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
  <groupId>com.sap.cloud.db.jdbc</groupId>
  <artifactId>ngdbc</artifactId>
  <version>2.18.14</version>
</dependency>

3. Configure application.properties

spring.datasource.url=jdbc:sap://localhost:39015/?databaseName=HXE
spring.datasource.username=SYSTEM
spring.datasource.password=YourPassword
spring.datasource.driver-class-name=com.sap.db.jdbc.Driver

spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=hana-group

4. Create Entity for Orders

import jakarta.persistence.*;
import java.time.LocalDateTime;

@Entity
public class Order {
    @Id
    private int id;
    private String product;
    private int quantity;
    private LocalDateTime createdAt;

    // getters and setters
}

5. Repository

import org.springframework.data.jpa.repository.JpaRepository;

public interface OrderRepository extends JpaRepository<Order, Integer> {
}

6. Kafka Consumer

import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.ObjectMapper;

@Service
public class OrderConsumer {
    private final OrderRepository repo;
    private final ObjectMapper mapper = new ObjectMapper();

    public OrderConsumer(OrderRepository repo) {
        this.repo = repo;
    }

    @KafkaListener(topics = "orders", groupId = "hana-group")
    public void consume(String message) throws Exception {
        Order order = mapper.readValue(message, Order.class);
        repo.save(order);
        System.out.println("Saved order: " + order.getProduct());
    }
}

7. Test the Flow

  1. Start Kafka and Spring Boot app.
  2. Produce a Kafka message:
    kafka-console-producer --broker-list localhost:9092 --topic orders
    Message format (JSON):
    {"id":1,"product":"Laptop","quantity":2,"createdAt":"2025-08-25T10:00:00"}
  3. The app will consume and save into SAP HANA Express.

image quote pre code