Connecting to the database v42.5.4.2

After the driver has loaded and registered itself with the DriverManager, the ListEmployees class can attempt to connect to the database server, as shown in the following code fragment:

String url = "jdbc:edb://localhost:5444/edb";
String user = "enterprisedb";
String password = "enterprisedb";
Connection con = DriverManager.getConnection(url, user, password);

All JDBC connections start with the DriverManager. The DriverManager class offers a static method called getConnection() that's responsible for creating a connection to the database. When you call the getConnection() method, the DriverManager must decide which JDBC driver to use to connect to the database. The decision is based on a URL that you pass to getConnection().

A JDBC URL takes the following general format:

jdbc:<driver>:<connection parameters>

The first component in a JDBC URL is always jdbc. When using the EDB Postgres Advanced Server JDBC Connector, the second component (the driver) is edb.

The Advanced Server JDBC URL takes one of the following forms:

jdbc:edb:<database>

jdbc:edb://<host>/<database>

jdbc:edb://<host>:<port>/<database>

The following table shows the various connection parameters.

NameDescription
hostThe host name of the server. Defaults to localhost.
portThe port number the server is listening on. Defaults to the EDB Postgres Advanced Server standard port number (5444).
databaseThe database name.

additional_connection_properties preferring_synchronous_secondary_database_servers