How to open a connection in JPA

I have an application in SpringBoot with JPA. When I lost connection, my application will send me an error message:

WARN 6812 --- [io-8080-exec-42] ohengine.jdbc.spi.SqlExceptionHelper: SQL Error: 17002, SQLState: 08006
ERROR 6812 --- [io-8080-exec-42] ohengine.jdbc.spi. SqlExceptionHelper: IO Error: socket out timer

After establishing a connection, I cannot use my EntityManager because I get:

WARN 6812 --- [io-8080-exec-50] ohengine.jdbc.spi.SqlExceptionHelper: SQL Error: 17008, SQLState: 08003
ERROR 6812 --- [io-8080-exec-50] ohengine.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-loan = true
spring.datasource.test-while-idle = true
spring.datasource.validation-query = SELECT 1;

What should I do to restore the connection to the database?

+3


source to share


1 answer


Try adding an external connection pool like HikariCP as Spring Boot will automatically detect and use it:

If HikariCP is available, we will use it.



If you are using the JDBC4 driver, the connection pool will check the connection before passing it to you. If you are using an older driver, you need to set this property:

connectionTestQuery

If your driver supports JDBC4, we strongly recommend that you do not install this property. This is for "legacy" databases that do not support the JDBC4 API Connection.isValid (). This is a query that will only run before you are given a pooled connection to confirm that the database connection is still alive. Try again to start the pool without this property, HikariCP will log an error if your driver is not JDBC4 so you know. Default: none

0


source







All Articles