Help Center/ TaurusDB/ Best Practices/ Best Practices for Client Connection Pools/ Best Practices for JDBC Connection Pools
Updated on 2026-10-19 GMT+08:00

Best Practices for JDBC Connection Pools

JDBC establishes a session with the database through a URL. The connection parameters in the URL directly determine the character set, encryption, and timeout behavior of the connection. Connection pools (such as Druid and HikariCP) reuse connections on top of JDBC, and URL parameters apply equally to each physical connection in the pool. This section uses the MySQL protocol (mysql-connector-j 8.0) as an example. The default values and descriptions of the parameters are based on the official Connector/J documentation.

Standard JDBC URL

The URL format is jdbc:mysql://<host>:<port>/<database>?key1=value1&key2=value2. Before the question mark (?), specify the protocol, host, port, and database. After the question mark (?), specify the connection parameters in the format of key=value. Separate multiple parameters with ampersands (&).

The following is an example (line breaks are added for better readability and should be removed in the actual configuration):

jdbc:mysql://<host>:3306/<database>
    ?connectTimeout=10000
    &socketTimeout=60000
    &tcpKeepAlive=true
    &autoReconnect=false
Table 1 Parameter description

Parameter

Default Value

Description

Recommended Value

Note

connectTimeout

0

Timeout interval for establishing a socket connection (ms)

10000

When a primary/standby switchover occurs or the network is disconnected, this parameter prevents application threads from being blocked in the connect phase for a long time. It takes effect only during the connection establishment phase and no longer applies once the connection is established.

socketTimeout

0

Socket read timeout (ms)

60000

If no data is returned within this period during a single read operation, the connection is interrupted.

When a connection is suspended due to a primary/standby switchover, lock wait, or page fetch blocking, the connection is automatically disconnected to prevent infinite thread waiting. This parameter value must be greater than the maximum query duration of applications. Otherwise, normal long-running queries may be terminated by mistake.

tcpKeepAlive

true

Whether to enable the TCP keepalive mechanism

true

This parameter determines whether to keep connections alive via OS-level mechanisms and check if the peer is alive. You are advised to set this parameter to true.

autoReconnect

false

Whether to automatically reconnect after a connection failure

false

It is not recommended by the official documentation to set this parameter to true. Reconnection is unreliable and may result in the loss of session status, temporary tables, transactions, and user variables.

You are advised to configure connectTimeout and socketTimeout simultaneously to cover the connection establishment and data read phases, respectively. If either parameter is set to 0, no timeout protection is provided for the corresponding phase. You are not advised to retain the default value 0 in the production environment.

The recommended values represent common settings in production and should be adjusted based on factors such as the maximum query duration of your applications.

Other Common Connection Parameters

The table below lists common parameters related to character sets, encryption, time zones, and performance. Configure them as required. For parameters that are less important or not listed, refer to the official website.

Table 2 Other common connection parameters

Parameter

Default Value

Description

Recommended Value

Note

sslMode

PREFERRED

SSL/TLS encryption mode

PREFERRED / REQUIRED

The default value is PREFERRED (encryption is performed if the server supports it; otherwise, plaintext is used). In the production environment, you are advised to set this parameter to REQUIRED to forcibly encrypt data. Ensure that TLS has been enabled on the server and the certificate is trusted.

useUnicode

true

Whether to process character transmission in Unicode mode

true

You are advised to retain the default value true and use it together with characterEncoding.

characterEncoding

Consistent with the database character set

Character set used for the connection

Consistent with the database character set (for example, utf8mb4)

You are advised to set it to the same value as the database character set.

serverTimezone

Consistent with the database time zone

Connection session time zone

Time zone where the database is located (for example, Asia/Shanghai)

You are advised to set it to the time zone where the database is located to avoid time deviation or time zone errors.