Updated on 2025-10-23 GMT+08:00

Database Connection Parameters

Function Prototype

JDBC provides three database connection methods.
  • DriverManager.getConnection(String url)
  • DriverManager.getConnection(String url, Properties info)
  • DriverManager.getConnection(String url, String user, String password)

Connection Parameters

Table 1 Database connection parameters

Parameter

Description

url

Database connection descriptor of the MySQL JDBC driver. The format is as follows:

jdbc:mysql://host:port/database
jdbc:mysql://host:port/database?param1=value1&param2=value2
NOTE:
  • database indicates the name of the database you want to connect. It cannot be left empty and must be specified.
  • host indicates the name or IP address of the database server. Only an IPv4 address is supported.
    • For security purposes, the primary database node forbids access from other nodes in the database without authentication. To access the primary database node from inside the database, deploy the JDBC program on the host where the primary database node is located and set host to 127.0.0.1. Otherwise, the error message "FATAL: Forbid remote connection with trust method!" may be displayed.
    • It is recommended that the service system be deployed outside the database. Otherwise, the database performance may be affected.
    • By default, the localhost is used to connect to the server.
  • port indicates the port number of the database server and cannot be left blank. You need to set the GUC parameter plat_compat_server_port on the server.
  • param indicates a database connection attribute.

    The parameter can be configured in the URL. The URL starts with a question mark (?), uses an equal sign (=) to assign a value to the parameter, and uses an ampersand (&) to separate parameters. You can also use the attributes of the Properties object for configuration.

  • value indicates the database connection attribute values.
  • The connectTimeout and socketTimeout parameters must be set for connection. If they are not set, the default value 0 is used, indicating that the connection will not time out. In the event of a network failure between a DN and the client, the client will be unable to receive ACK packets from the DN. The timeout-and-retransmission mechanism will kick in to retransmit the packets until the client successfully receives them. A timeout error is reported only when the timeout interval reaches the default value 600s. As a result, the RTO is high.
  • You are advised to ensure the validity of the URL when using the standard JDBC API to establish a connection. An invalid URL may cause an exception, and the exception contains the original URL character string, which may cause sensitive information leakage.

info

Database connection attribute. For details, see Connection Attributes of the info Parameter.

user

Database user.

password

Password of the database user.

Connection Attributes of the info Parameter

All connection attribute names of the info parameter are case-sensitive. Table 2 describes the common attributes.

Table 2 Connection attributes of the info parameter

Attribute

Description

Value

user

It specifies the database user who creates the connection.

Attribute type: STRING

password

It specifies the password of the database user.

Attribute type: STRING

useSSL

It specifies that the database is connected in SSL mode.

Attribute type: BOOLEAN

Value range:

  • true: The database is connected in SSL mode.
  • false: The database is not connected in SSL mode.

verifyServerCertificate

It specifies whether the client verifies the server certificate when the database is connected in SSL mode.

Attribute type: BOOLEAN

Value range:

  • true: The client verifies the server certificate.
  • false: The client does not verify the server certificate.

Default value: true

trustCertificateKeyStoreUrl

It specifies the URL of the trusted root certificate keystore.

Attribute type: STRING

trustCertificateKeyStoreType

It specifies the key storage type of the trusted root certificate.

Attribute type: STRING

Default value: JKS

trustCertificateKeyStorePassword

It specifies the password of the trusted root certificate keystore.

Attribute type: STRING

clientCertificateKeyStoreUrl

It specifies the URL of the client certificate keystore.

Attribute type: STRING

clientCertificateKeyStoreType

It specifies the key storage type of the client certificate keystore.

Attribute type: STRING

Default value: JKS

clientCertificateKeyStorePassword

It specifies the password of the client certificate keystore.

Attribute type: STRING

allowPublicKeyRetrieval

It specifies whether the client obtains the public key from the server.

Attribute type: BOOLEAN

Value range:

  • true: The client obtains the public key from the server.
  • false: The client does not obtain the public key from the server.

Default value: false

rewriteBatchedStatements

It specifies whether SQL statements that are batch executed can be rewritten.

Attribute type: BOOLEAN

Value range:

  • true: Combine N insert statements into one: insert into TABLE_NAME values(values1, ..., valuesN), ..., (values1, ..., valuesN)
  • false: Do not rewrite SQL statements during batch insertion.

Default value: false

allowMultiQueries

It specifies whether multiple SQL statements can be batch executed.

Attribute type: BOOLEAN

Value range:

  • true: Multiple SQL statements can be batch executed.
  • false: Multiple SQL statements cannot be batch executed.

Default value: false

autoReconnect

It specifies whether the client automatically reconnects to the server after connection interruption.

Attribute type: BOOLEAN

Value range:

  • true: The client automatically reconnects to the server after connection interruption.
  • false: The client does not automatically reconnect to the server after connection interruption.

Default value: false

useUnicode

It specifies whether the Unicode encoding is used.

Attribute type: BOOLEAN

Value range:

  • true: The client uses the Unicode encoding.
  • false: The client does not use the Unicode encoding.

Default value: false

characterEncoding

It specifies the character set.

NOTE:

The character set on the client must be the same as that on the server. If this parameter is not set, for driver 8.0.25 and earlier, the client attempts to use the default character set of the server. For driver 8.0.26 or later, the client uses the default sorting rule of UTF8mb4.

Attribute type: STRING

connectTimeout

It specifies the timeout interval for connecting to a server OS. If the time taken to connect to a server OS exceeds the value specified, the connection is interrupted. When multiple IP addresses are configured in the URL, it indicates the timeout interval for connecting to a single IP address.

Attribute type: INTEGER

Unit: ms

Value range: 0 to 2147483647. The value 0 indicates that no timeout occurs.

Default value: 0

socketTimeout

It specifies the timeout interval for a socket read operation. If the time taken to read data from a server exceeds the value specified, the connection is closed.

Attribute type: INTEGER

Unit: ms

Value range: 0 to 2147483647. The value 0 indicates that no timeout occurs.

Default value: 0