2

is there any way to set spring boot to reconnect Oracle if the connection is die or disconnected?

My current spring boot setting:

spring.datasource.url=jdbc:oracle:${db.driver}:@${db.host}:${db.port}:${db.sid}
spring.datasource.username=${db.userName}
spring.datasource.password=${db.password}
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

clarification: I want to reconnect the DB again when it stopped and then started again.

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Asfbar
  • 259
  • 6
  • 21
  • Possible duplicate of [Spring Boot JPA - configuring auto reconnect](http://stackoverflow.com/questions/22684807/spring-boot-jpa-configuring-auto-reconnect) – Andreas Brunnet Aug 17 '16 at 06:21
  • that solution just keep the connection alive using a select statement. i want to reconnect if the DB got down and then back again. – Asfbar Aug 17 '16 at 06:25
  • 1
    Then use a connection pool like any proper developer. – Kayaman Aug 17 '16 at 06:27
  • OK thanks. i'm new with Java and Spring. can you please be more specific? thank you. – Asfbar Aug 17 '16 at 06:29
  • See this answer http://stackoverflow.com/questions/30451470/connection-to-db-dies-after-424-in-spring-boot-jpa-hibernate/30455408#30455408 . Although written for MySQL the general advice goes for every database. Check when idle and on checkout. You might want to check which validation query to use. Or if you are using a proper JDBC4 driver and HikariCP you don't really need one as validation is done using plain JDBC4 features. – M. Deinum Dec 09 '16 at 11:25

1 Answers1

-1

The error that you got is related to DB side not java side. Most of time it happens when db schemaName/name/password is wrong.

I haven't tried it with this ?autoReconnect=true before but I would suggest you to implement a simple thread that check connection every 5-10 sec (also you can add sleep time as well),if there is no connection try to connect to db again.

orkn_akgl
  • 721
  • 7
  • 14