This guide shows how to call stored procedures in SAP HANA Express from a Spring Boot application. Follow and try directly.
1. Create Stored Procedure in HANA
- Connect to SAP HANA Studio or Database Explorer and create a procedure:
CREATE PROCEDURE GET_TOTAL_ORDERS (OUT total INT)
AS
BEGIN
SELECT COUNT(*) INTO total FROM ORDERS;
END;
2. Project Setup
Generate a Spring Boot project with Spring Initializr :
- Dependencies: Spring Web, Spring Data JPA
Add the SAP HANA JDBC driver (ngdbc.jar) manually into Maven as explained before.
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.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.HANARowStoreDialect
4. Call Stored Procedure with JPA
import jakarta.persistence.*;
@Entity
@NamedStoredProcedureQuery(
name = "Order.getTotalOrders",
procedureName = "GET_TOTAL_ORDERS",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "total", type = Integer.class)
})
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String customer;
private double amount;
// getters and setters
}
5. Repository Interface
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.CrudRepository;
public interface OrderRepository extends CrudRepository<Order, Long> {
@Procedure(name = "Order.getTotalOrders")
int getTotalOrders();
}
6. Test Stored Procedure
In DemoApplication.java:
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
CommandLineRunner run(OrderRepository repo) {
return args -> {
repo.save(new Order("Alice", 500));
repo.save(new Order("Bob", 1500));
int total = repo.getTotalOrders();
System.out.println("Total orders: " + total);
};
}
}
Run with:
mvn spring-boot:run
You should see the total orders printed in the console.
image quote pre code