This page in other versions: Unsupported versions: 7.0

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


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


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


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);

Submit correction

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.

Privacy Policy | About PostgreSQL
Copyright © 1996-2016 The PostgreSQL Global Development Group