This guide shows how to set up a Spring Boot project that connects to SAP HANA Express using the official JDBC driver. The steps are simple and can be followed directly.
1. Create a Spring Boot Project
You can generate a project using Spring Initializr :
- Project: Maven
- Language: Java
- Spring Boot: Latest stable version
- Dependencies: Spring Data JPA, Spring Web
- Download and extract the generated project.
2. Add SAP HANA JDBC Driver
SAP HANA JDBC driver is not available in Maven Central. You must download it manually.
3. Configure pom.xml
Add the dependency for the installed driver:
<dependency>
<groupId>com.sap.cloud.db.jdbc</groupId>
<artifactId>ngdbc</artifactId>
<version>2.18.14</version>
</dependency>
4. Configure application.properties
Add the SAP HANA database connection:
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
⚠️ Replace localhost, 39015, and YourPassword with your actual SAP HANA Express connection details.
5. Create a Simple Entity
Example: User.java
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
// getters and setters
}
6. Create a Repository
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Long> {
}
7. Test the Connection
In src/main/java/.../DemoApplication.java:
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
CommandLineRunner init(UserRepository repo) {
return args -> {
repo.save(new User("Alice"));
repo.findAll().forEach(user -> System.out.println(user.getName()));
};
}
}
Run the app with:
mvn spring-boot:run
If the setup is correct, you will see Alice printed in the console
image quote pre code