java - How to reopen connection in JPA -
i have app in springboot jpa. when lost connection app send me error:
warn 6812 --- [io-8080-exec-42] o.h.engine.jdbc.spi.sqlexceptionhelper : sql error: 17002, sqlstate: 08006
error 6812 --- [io-8080-exec-42] o.h.engine.jdbc.spi.sqlexceptionhelper : io error: socket read timed out
after estabilishin connection can't use entitymanager, because get:
warn 6812 --- [io-8080-exec-50] o.h.engine.jdbc.spi.sqlexceptionhelper : sql error: 17008, sqlstate: 08003
error 6812 --- [io-8080-exec-50] o.h.engine.jdbc.spi.sqlexceptionhelper : closed connection
my connection properties:
spring.datasource.driverclassname=oracle.jdbc.driver.oracledriver
spring.datasource.url=jdbc:oracle:thin:@...:..:..
spring.datasource.username=...
spring.datasource.password=...
spring.datasource.test-on-borrow=true
spring.datasource.test-while-idle=true
spring.datasource.validation-query=select 1;
what should reconnect db connection?
try adding external connection pool, such hikaricp, since spring boot automatically detect , use it:
if hikaricp available use it.
if using jdbc4 driver, connection pool validate connection before handing you. if using older driver need set property:
connectiontestquery
if driver supports jdbc4 recommend not setting property. "legacy" databases not support jdbc4 connection.isvalid() api. query executed before connection given pool validate connection database still alive. again, try running pool without property, hikaricp log error if driver not jdbc4 compliant let know. default: none
Comments
Post a Comment