Additional Connection Properties

In addition to the standard connection parameters, the Advanced Server JDBC driver supports connection properties that control behavior specific to EnterpriseDB. You can specify these properties in the connection URL or as a Properties object parameter passed to DriverManager.getConnection(). Listing 1.2 demonstrates how to use a Properties object to specify additional connection properties:

Listing 1.2

String url = "jdbc:edb://localhost/edb";
Properties props = new Properties();

props.setProperty("user", "enterprisedb");
props.setProperty("password", "enterprisedb");
props.setProperty("sslfactory", "com.edb.ssl.NonValidatingFactory");
props.setProperty("ssl", "true");

Connection con = DriverManager.getConnection(url, props);

Note

By default the combination of SSL=true and setting the connection URL parameter sslfactory=org.postgresql.ssl.NonValidatingFactory encrypts the connection but does not validate the SSL certificate. To enforce certificate validation, you must use a Custom SSLSocketFactory. For more details about writing a Custom SSLSocketFactory, review the PostgreSQL JDBC driver documentation.

To specify additional connection properties in the URL, add a question mark and an ampersand-separated list of keyword-value pairs:

String url = "jdbc:edb://localhost/edb?user=enterprisedb&ssl=true";

Some of the additional connection properties are shown in the following table:

Table 5-2 - Additional Connection Properties

Name Type Description
user String The database user on whose behalf the connection is being made.
password String The database user’s password.
ssl Boolean Requests an authenticated, encrypted SSL connection
loglevel Integer

The value of loglevel determines the amount of detail printed to the DriverManager’s current value for LogStream or LogWriter. It currently supports values of:

com.edb.Driver.DEBUG

com.edb.Driver.INFO

Set the value of loglevel to INFO to include sparse log information or to DEBUG to produce significant detail.

charSet String The value of charSet determines the character set used for data sent to or received from the database.
prepareThreshold Integer The value of prepareThreshold determines the number of PreparedStatement executions required before switching to server side prepared statements. The default is five.
loadBalanceHosts Boolean In default mode (disabled) hosts are connected in the given order. If enabled, hosts are chosen randomly from the set of suitable candidates.
targetServerType String Allows opening connections to only servers with the required state. The allowed values are any, master, secondary, preferSecondary, and preferSyncSecondary. The master/secondary distinction is currently done by observing if the server allows writes. The value preferSecondary tries to connect to secondaries if any are available, otherwise allows connecting to the master. The Advanced Server JDBC Connector supports preferSyncSecondary, which permits connection to only synchronous secondaries or the master if there are no active synchronous secondaries. See Section 5.2.2 for information on preferSyncSecondary. Note: The values slave, preferSlave, and preferSyncSlave have been deprecated as they have been replaced by the “secondary” values. The “slave” values are currently still supported, and the use of the terms “slave” and “secondary” provide the same functionality, however, it is advised to use the “secondary” values.
skipQuotesOnReturning Boolean When set to true, column names from the RETURNING clause are not quoted. This eliminates a case-sensitive comparison of the column name. When set to false (the default setting), column names are quoted.