With JDBC, a database is represented by a URL (Uniform Resource Locator). With PostgreSQL™, this takes one of the following forms:
jdbc:postgresql:database
jdbc:postgresql://host/database
jdbc:postgresql://host:port/database
The host name of the server. Defaults to localhost. To specify an IPv6 address your must enclose the host parameter with square brackets, for example:
jdbc:postgresql://[::1]:5740/accounting
The port number the server is listening on. Defaults to the PostgreSQL™ standard port number (5432).
The database name.
To connect, you need to get a Connection instance from JDBC. To do this, you use the DriverManager.getConnection() method:
Connection db = DriverManager.getConnection(url, username, password);