Set the following information in the connection string of the DriverManager class, or in the data source.
Argument | Explanation |
---|---|
host1 | Specify the IP address or host name. |
port1 | Specify the port number for the connection. |
database_name | Specify the database name. |
targetServer | Specify the selection sequence of the servers to which the application will connect. |
sslmode | Specify this to encrypt communications. By default, this is disabled. The setting values for sslmode are as follows: disable: Connect without SSL require: Connect always with SSL verify-ca: Connect with SSL, using a certificate issued by a trusted CA (*1) verify-full: Connect with SSL, using a certificate issued by a trusted CA to verify if the server host name matches the certificate (*1) |
sslservercertcn | This parameter is enabled only to perform SSL authentication (sslmode=verify-full). Specify the server certificate CN. If this is omitted, the value will be null, and the server certificate CN will be authenticated using the host name specified in host. |
*1: If specifying either "verify-ca" or "verify-full", the CA certificate file can be specified using connection string sslrootcert.
Specify the following URL in the API of the DriverManager class:
jdbc:postgresql://host1[:port1],host2[:port2]/database_name[?targetServer={primary | prefer_standby | any}][&sslmode=verify-full&sslrootcert=cACertificateFile&sslservercertcn=targetServerCertificateCN]
If the target server is omitted, the default value "primary" is used.
When using IPV6, specify the host in the "[host]" (with square brackets) format.
[Example]
jdbc:postgresql://[2001:Db8::1234]:26500,192.168.1.1:26500/database_name
Specify the properties of the data source in the following format:
source.setServerName("host1[:port1],host2[:port2]"); source.setTargetServer("primary"); source.setSslmode("verify-full"); source.setSslrootcert("cACertificateFile"); source.setSslservercertcn("targetServerCertificateCN");
If the port number is omitted, the value specified in the portNumber property will be used. Also, if the portNumber property is omitted, the default is 26500.
If the target server is omitted, the value will be primary.
When using IPV6, specify the host in the "[host]" (with square brackets) format.
[Example]
source.setServerName("[2001:Db8::1234]:26500,192.168.1.1:26500");
Note
If using the connection parameter loginTimeout, the value will be applied for the time taken attempting to connect to all of the specified hosts.