データベースへの接続

ドライバーが DriverManager で自身をロードして登録した後、次のコードフラグメントに示すように、 ListEmployees クラスはデータベースサーバーへの接続を試行できます。

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 is 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; that decision is based on a URL (Uniform Resource Locator) that you pass to getConnection().

JDBCURLは次の一般的な形式を取ります。

jdbc:<driver>:<connection parameters>

JDBCURLの最初のコンポーネントは常に jdbc です。AdvancedServerJDBCConnectorを使用する場合、2番目のコンポーネント(ドライバー)は edb です。

AdvancedServerJDBCURLは、次のいずれかの形式を取ります。

jdbc:edb:<database>

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

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

次の表に、さまざまな接続パラメーターを示します。

表-接続パラメーター

お名前

説明

ホスト

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

港

サーバーがリッスンしているポート番号。デフォルトはAdvancedServerの標準ポート番号(5444)です。

データベース

データベース名。