Spring Boot DB2 and MSSQL Configuration

By default Spring boot does a lot for you in datasource configuration, but if you’re using two separate database types – DB2, MSSQL, MySQL, Oracle, etc. It doesn’t know how to infer which database type each is, so if you are configuring multiple different database types in Spring you need to specify the jpa.database type. In a yaml configuration your datasources should be defines like so.

spring:
  datasource:
    url: jdbc:sqlserver://${server}:${port};databaseName=${databaseName}
    username: ${username}
    password: ${password}
  jpa:
    database: sql_server
db2:
  datasource:
    jdbcurl: jdbc:db2://${server}:${port}/${databaseName}
    username: ${username}
    password: ${password}
  jpa:
    database: db2
Matt Busche's Picture

About Matt Busche

Software Engineer and Wheel of Fortune Expert If this article helped you, please consider buying me a book.

Des Moines, IA https://www.mrbusche.com