JDBC Driver for EnterpriseDB

Build 22.0.8479

Code からの接続

このセクションでは、JDBC DriverManager またはEnterpriseDBDataSource インターフェースに接続する方法について説明します。

DriverManager で接続

DriverManager クラスを使用して接続する場合、CData JDBC Driver for EnterpriseDB はJDBC 規則に従います。最初にEnterpriseDB ドライバークラスをロードします。次に、接続を作成します。

ドライバーのロード

JDBC 4.0仕様では、次の手順はオプションです。
Class.forName("cdata.jdbc.enterprisedb.EnterpriseDBDriver");

接続の確立

静的なDriverManager クラスのgetConnection メソッドで接続文字列を指定します。接続文字列を"jdbc:enterprisedb:" で始めます。一般的な接続文字列は以下のとおりです。

Connection conn = DriverManager.getConnection("jdbc:enterprisedb:User=postgres;Password=admin;Database=postgres;Server=127.0.0.1;Port=5444");
または、Properties オブジェクトを使用して接続オプションを準備できます。Properties オブジェクトをDriverManager に渡します。
Properties prop = new Properties();
prop.setProperty("User","postgres");
prop.setProperty("Password","admin");
prop.setProperty("Database","postgres");
prop.setProperty("Server","127.0.0.1");
prop.setProperty("Port","5432");

Connection conn = DriverManager.getConnection("jdbc:enterprisedb:",prop);

EnterpriseDBDataSource クラスで接続

以下の例に示すように、EnterpriseDBDataSource クラスを使用してプールされた接続を作成できます。詳しくは、接続プール を参照してください。

次の例は、プールされたConnection オブジェクトをインスタンス化します。

EnterpriseDBDataSource ds = new EnterpriseDBDataSource("jdbc:enterprisedb:UseConnectionPooling=true;User=postgres;Password=admin;Database=postgres;Server=127.0.0.1;Port=5444"); 
Connection conn = ds.getConnection();

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479