select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Unsupported versions: 7.0
Historical version. PostgreSQL 7.0 reached end of support in May 2005. See the current manual for supported releases.

Connecting to the Database

With JDBC, a database is represented by a URL (Uniform Resource Locator). With Postgres, this takes one of the following forms:

  • jdbc:postgresql:database

  • jdbc:postgresql://host/database

  • jdbc:postgresql://hostport/database

where:
host

The hostname of the server. Defaults to "localhost".

port

The port number the server is listening on. Defaults to the Postgres standard port number (5432).

database

The database name.

To connect, you need to get a Connection instance from JDBC. To do this, you would use the DriverManager.getConnection() method:

Connection db = DriverManager.getConnection(url,user,pwd);
    

Report a documentation issue

Read the upstream documentation. For corrections, first check the current manual.