Creating a new connection manually gets added to Hikari connection pool

Viewed 253

In my Spring Boot application does a connection created manually using DriverManager get added to the HikarCP connection pool or not.

I have the following properties for Hikari connection pool:

spring.datasource.hikari.maximum-pool-size=5
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.minimum-idle=1
spring.datasource.hikari.leakDetectionThreshold=240000
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.maxLifetime=300000 

And in one of the classes I'm creating a new connection manually.

try (Connection con = DriverManager.getConnection(url, user, password)) {   
    try (PreparedStatement stmt = con.prepareStatement(updatedCommand)) {
        stmt.execute();
    } catch (SQLException sqlException) {
        log.error("Error while executing the sql command , message {}", sqlException.getLocalizedMessage());
    }
} catch (Exception e) {
    log.error("Error while connecting to Database, message {}", e.getLocalizedMessage());
}

Does the manually created connection get added to Hikari's connection pool or not.

If it's added to Hikari's managed connection pool then does it close this connection according the configurations if it sits idle?

1 Answers

No, connections created through DriverManager will not be added to any connection pool*.

I'm not sure why you would think that a connection created like that would get added to Hikari, because Hikari is not involved in any way when you use DriverManager.


* In theory, a JDBC driver itself could have an internal connection pool, but I'm not aware of any 'standard' drivers doing this.

Related