Spring boot: Oracle RAC DB connection configuration

4k views Asked by At

In Spring boot application, Need to configure Oracle RAC DB URL. Can someone explain how to configure the Oracle RAC URL in application.properties?

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL={PROTOCOL})(HOST={{URL})(PORT={PORT})))(CONNECT_DATA=(SERVICE_NAME={SERVICE_NAME})))

Have verified the Spring boot official doc and didn't find anything related. Even verified in the Common Properties and can't find any references.

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

Thanks for your help in advance!

2

There are 2 answers

0
Alien On

Try with below.

jdbc:oracle:thin:@(DESCRIPTION=
    @    (LOAD_BALANCE=on)
    @    (ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
    @    (ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521))
    @    (CONNECT_DATA=(SERVICE_NAME=service_name)))

OR

# Oracle settings
spring.datasource.url=jdbc:oracle:thin:@localhost:1522:orcl
spring.datasource.username=HIBERNATE_TEST
spring.datasource.password=HIBERNATE_TEST
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver

OR

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db1.myco.com)(PORT=1604))
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db2.myco.com)(PORT=1604)))
(CONNECT_DATA=(SERVICE_NAME=mydb1.myco.com)(SERVER=DEDICATED)))

Sources :

https://docs.oracle.com/cd/E57185_01/EPMIS/apbs01s01.html

https://dzone.com/articles/configuring-spring-boot-for-oracle

1
janardhan sharma On

This is what i did to connect to postgres in my project and it is in production now. For Oracle it is exactly same. In fact for any other RDBMS.

Add the properties in the application.yml or the application.properties in the spring boot project.

The below is yml configuration.

 spring:
  jpa:
    database: POSTGRESQL
    show-sql: false
  datasource:
    platform: postgres
    url: jdbc:postgresql://123.3.4.89.com:1234/DatabaseName
    username: user123
    password: pass123
    driver-class-name: org.postgresql.Driver
    testWhileIdle: true
    validationQuery: SELECT 1

Then add the driver in the pom or the gradle build file which build tool you are using. And the jpa jar of spring boot.

This was entry in the build.gradle file.

compile ('org.springframework.boot:spring-boot-starter-data-jpa')
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.2'

Thats it, now you can create your repositories and start pushing and fetching data in the Db.

Hope this helps, cheers !!!