接続の確立
JDBC データソースの作成
Java アプリケーションから接続するJDBC データソースを作成できます。CData JDBC Driver for Cloudant に基づくJDBC データソースの作成は、3つの基本ステップで構成されます。
- ドライバーのJAR ファイルをクラスパスに追加します。JAR ファイルはインストールディレクトリの[lib]サブフォルダ内にあります。.lic ファイルはJAR ファイルと同じフォルダ内に配置される必要があることに注意してください。
- ドライバークラスを入力します。次に例を示します。
cdata.jdbc.cloudant.CloudantDriver
- JDBC URL を入力します。次に例を示します。
jdbc:cloudant:User=abc123; Password=abcdef; or jdbc:cdata:cloudant:User=abc123; Password=abcdef;
上記の2つ目の形式は、同じURL 形式を使用しているドライバー間でアプリケーションに競合がある場合は、CData ドライバーを使用していることを確認するために常に使用できます。URL は "jdbc:cloudant:" または"jdbc:cdata:cloudant:" のいずれかから始まり、任意の接続プロパティの名前と値のペアをセミコロン区切りで入力します。
Cloudant への認証
Cloudant は3種類の認証をサポートします。- Auto(デフォルト):本製品 は、設定された他の接続プロパティに基づいて認証方法を決定します。
- Basic:基本的なユーザー名 / パスワード認証。AuthScheme をBasic に設定します。
- OAuth:OAuth 規格に基づいた認証を行います。AuthScheme をOAuth に設定し、Cloudant インスタンスの APIKey とURL の値を指定します。
IBM Cloudant Legacy
IBM Cloudant Legacy 経由で接続するには、有効なIBM Cloudant サービスクレデンシャルを持っていることを確認してください。IBM Cloudant のサービスクレデンシャルを作成するには:
- IBM Cloud ダッシュボードにログインします。
- Menu icon -> Resource List に移動し、IBM Cloudant サービスインスタンスを開きます。
- メニューで、Service credentials をクリックします。
- New credential をクリックします。Cloudant はAdd new credential ウィンドウを表示します。
- 新しい資格情報の名前を入力します。
- Add をクリックします。 資格情報がService credentials テーブルに追加されます。
- Actions -> View credentials をクリックします。
- JSON ファイルからUser およびPassword の値を取得します。
取得した値を使用して、User およびPassword を設定します。
IBM Cloud IAM
IBM Cloud IAM is OAuth-based authentication accessed via a web browser.To authenticate to IBM Cloud, set AuthScheme to OAuth and supply the ApiKey and the Url of the target Cloudant instance (for example, https://0c9d3837-8304-4aab-a65a-648169970943-bluemix.cloudant.com).
After setting InitiateOAuth to GETANDREFRESH (default), you are ready to connect.
When you connect, the 本製品 completes the OAuth process.
- Extracts the access token and authenticates requests.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
Retrieving OAuth connection properties
To retrieve the OAuth connection properties:- Create an account in IBM Cloud.
- Obtain the ApiKey:
- Log in to your IBM Cloud account.
- Navigate to Platform API Keys page.
- To create a new API Key, click Create an IBM Cloud API Key. Cloudant displays a pop-up form.
- Specify the API Key name and click Create. Cloudant displays the
ApiKey you just created.
Save this information for future reference.
Registering a new instance of Cloudant
If you do not already have Cloud Object Storage in your IBM Cloud account, you can install an instance of SQL Query in your account:
- Log in to your IBM Cloud account.
- Navigate to the Cloudant page.
- Choose a name for your instance and click Create. You are redirected to that Cloudant instance.
ローカルインスタンスへの認証
Cloudant は、バージョン1.1.0以上のローカルインスタンスのデータへの認証をサポートします。ローカルインスタンスへの認証を行うには、次のパラメータを設定します。
- Url:ローカルインスタンスのURL。例: http://localhost:8006
- User:ユーザーネーム。
- Password:パスワード。