1

Could someone with experience please share recommendations on configuring a db2 database with a Spring Boot App?

Creating a Spring Boot app that will access a db2 table using JpaRepository to render results from query in an HTML view using Thymeleaf.

Looking for a general explanation on how to configure a Spring Boot App that will access a db2 table using Spring Data Jpa. Specifically, what would I need in my build.gradle and application.properties to make this happen?

wallwalker
  • 513
  • 3
  • 14
  • 25
  • I think this can help https://stackoverflow.com/questions/26130148/challenges-starting-off-with-gradle-spring-and-db2 – lak Sep 13 '19 at 16:11

2 Answers2

2

i think this may help you i used it in simple poc


# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
spring.datasource.url=jdbc:db2://localhost:50000/EXAMPLE
spring.datasource.username=db2inst1
spring.datasource.password=db2inst1-pwd
spring.datasource.driver-class-name=com.ibm.db2.jcc.DB2Driver
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update): with "create-drop" the database
# schema will be automatically created afresh for every start of application
spring.jpa.hibernate.ddl-auto=create-drop

and you can read this article may help you here and here and i recommend u the second one

fathy elshemy
  • 476
  • 4
  • 15
-1

To work with Spring Boot and embedded in-memory database, such as H2, you need just to add its dependency to your project:

<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <scope>runtime</scope>-->
</dependency>

and, for example, Spring Data JPA starter:

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

Then Spring Boot will make the rest of autoconfiguring itself.

Thus you can start to work with your entities, eg:

@Entity
public class MyEntity {
    @Id
    @GeneratedValue
    private Integer id;

    // other stuff
}

And repositories:

public interface MyEntityRepo extends JpaRepository<MyEntity, Integer> {
}

Additional info:

Cepr0
  • 24,708
  • 7
  • 67
  • 95