データベースへの接続

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

JDBC を使用する場合、データベースは URL(Uniform Resource Locator)で表されます。Postgres では、これは下の形式のどれか1つになります。

where: ここで:

host

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

サーバのホスト名。デフォルトは "localhost" です。

port

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

サーバが監視しているポート番号。デフォルトは Postgres の標準的な ポート番号(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:

接続するために、JDBC から Connection インスタ ンスを入手します。これには、下のように DriverManager.getConnection() メソッドを使います。

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