Run SQL statement at beginning of each DB connection in Spring Boot

前端 未结 1 404
予麋鹿
予麋鹿 2021-01-06 12:06

How can I run a custom SQL statement directly after obtaining a DB connection with Spring Boot?

The SQL needs to be run each time a new connection is established.

相关标签:
1条回答
  • 2021-01-06 12:38

    Tomcat Jdbc Connection pool has a parameter "initSQL" https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

    It looks like you can configure each pool parameter in your .properties file (@see https://stackoverflow.com/a/25573035/280244)

    So give a try,

    Spring Boot before 1.4:

    spring.datasource.initSQL=ALTER SESSION SET CURRENT_SCHEMA=xxxx
    

    Spring Boot 1.4 or later:

    spring.datasource.tomcat.initSQL=ALTER SESSION SET CURRENT_SCHEMA=xxxx
    
    0 讨论(0)
提交回复
热议问题