JDBC Driver for GraphQL

Build 23.0.8839

Code からの接続

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

DriverManager で接続

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

ドライバーのロード

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

接続の確立

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

Connection conn = DriverManager.getConnection("jdbc:graphql:AuthScheme=OAuth;OAuthVersion=2.0;CallbackURL=http://localhost:33333;OauthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;OAuthAccessTokenURL=https://mysite.com/login/oauth/access_token;");
または、Properties オブジェクトを使用して接続オプションを準備できます。Properties オブジェクトをDriverManager に渡します。
prop.setProperty("AuthScheme","OAuth");
prop.setProperty("OAuthVersion","2.0");
prop.setProperty("CallbackURL","http://localhost:33333");
prop.setProperty("OauthClientId","MyOAuthClientId");
prop.setProperty("OAuthClientSecret","MyOAuthClientSecret");
prop.setProperty("OAuthAccessTokenURL","https://mysite.com/login/oauth/access_token");

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

GraphQLDataSource クラスで接続

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

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

GraphQLDataSource ds = new GraphQLDataSource("jdbc:graphql:UseConnectionPooling=true;AuthScheme=OAuth;OAuthVersion=2.0;CallbackURL=http://localhost:33333;OauthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;OAuthAccessTokenURL=https://mysite.com/login/oauth/access_token;"); 
Connection conn = ds.getConnection();

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839