Code からの接続
このセクションでは、JDBC DriverManager またはWorkdayDataSource インターフェースに接続する方法について説明します。
DriverManager で接続
DriverManager クラスを使用して接続する場合、CData JDBC Driver for Workday はJDBC 規則に従います。最初にWorkday ドライバークラスをロードします。次に、接続を作成します。
ドライバーのロード
JDBC 4.0仕様では、次の手順はオプションです。Class.forName("cdata.jdbc.workday.WorkdayDriver");
接続の確立
静的なDriverManager クラスのgetConnection メソッドで接続文字列を指定します。接続文字列を"jdbc:workday:" で始めます。一般的な接続文字列は以下のとおりです。
Connection conn = DriverManager.getConnection("jdbc:workday:ConnectionType=SOAP;User=myuser;Password=mypassword;Tenant=mycompany;BaseURL=https://wd3-impl-services1.workday.com");
または、Properties オブジェクトを使用して接続オプションを準備できます。Properties オブジェクトをDriverManager に渡します。
Properties prop = new Properties();
prop.setProperty("ConnectionType","SOAP");
prop.setProperty("User","myuser");
prop.setProperty("Password","password");
prop.setProperty("Tenant","mycompany");
prop.setProperty("BaseURL","https://wd3-impl-services1.workday.com");
Connection conn = DriverManager.getConnection("jdbc:workday:",prop);
WorkdayDataSource クラスで接続
以下の例に示すように、WorkdayDataSource クラスを使用してプールされた接続を作成できます。詳しくは、接続プール を参照してください。
次の例は、プールされたConnection オブジェクトをインスタンス化します。
WorkdayDataSource ds = new WorkdayDataSource("jdbc:workday:UseConnectionPooling=true;ConnectionType=SOAP;User=myuser;Password=mypassword;Tenant=mycompany;BaseURL=https://wd3-impl-services1.workday.com");
Connection conn = ds.getConnection();