Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send application name when connecting to an Oracle DB using HikariCP in Spring

Tags:

I have a Spring Boot 1.4.7 application that I am currently updating to version 2.0.5. The application connects to an Oracle DB using JDBC using the following configuration:

spring:
  jpa:
    database-platform: org.hibernate.dialect.Oracle12cDialect
  datasource:
    url: jdbc:oracle:thin:@<db_server>
    username: ${credentials.database.username}
    password: ${credentials.database.password}
    driver-class: oracle.jdbc.OracleDriver.class
    platform: oracle
    tomcat:
      connection-properties: v$session.program=${spring.application.name}

After updating the application to Spring Boot 2.0.5 the application name sent to the server is JDBC Thin Client instead of ${spring.application.name}. The reason for this seems to be the switch to HikariCP as the default connection pool in Spring 2.x. How would I migrate this configuration to Hikari in a way that allows me to send a custom property for v$session.program to the db?

What I have tried:

  • Appending ?ApplicationName=<name> to the JDBC url.
  • Solutions mentioned in this Stackoverflow question
  • Setting System.setProperty("oracle.jdbc.v$session.program", <name>)
  • Setting spring.datasource.hikari.data-source-properties.v$session.program: <name> in the application.yml
like image 265
Joba Avatar asked Oct 12 '18 12:10

Joba


People also ask

How does HikariCP connection pool work?

"HikariCP is solid high-performance JDBC connection pool. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools may significantly reduce the overall resource usage." - You can find out more here.

What is the use of HikariCP in spring boot?

Hikari is a JDBC DataSource implementation that provides a connection pooling mechanism. Compared to other implementations, it promises to be lightweight and better performing.


1 Answers

In yaml, the dollar sign is escaped.

spring.datasource.hikari.data-source-properties.v$session.program: <name>

com.zaxxer.hikari.HikariConfig : dataSourceProperties............{password=<masked>, vsession.program=<name>}

Try this.

spring:
  datasource:
    hikari:
      data-source-properties: v$session.program=name
like image 50
yeonguk kim Avatar answered Oct 02 '22 13:10

yeonguk kim