Establishing a Connection
Creating a JDBC Data Source
You can create a JDBC data source to connect from your Java application, based on CData JDBC Driver for Cloudant.Follow these steps:
- Add the driver JAR file to the classpath. The JAR file is located in the installation directory's lib subfolder. Ensure that the .lic file is located in the same folder as the JAR file.
- Provide the driver class. For example:
cdata.jdbc.cloudant.CloudantDriver
- Provide the JDBC URL. For example:
jdbc:cloudant:User=abc123; Password=abcdef;
Or, if there is a conflict in your application between drivers using the same URL format, use this form to ensure that you are using the CData driver:
jdbc:cdata:cloudant:User=abc123; Password=abcdef;
Ensure that the URL starts with either jdbc:cloudant: or jdbc:cdata:cloudant:. The URL can include any of the connection properties in name-value pairs separated with semicolons.
Authenticating to Cloudant
Cloudant supports two types of authentication:- OAuthAPIKey
- Basic
Prerequisite
For OAuthAPIKey and Basic authentication methods, you must have a Cloudant instance in your IBM Cloud account. If you do not already have a Cloudant instance, create one as follows:- Log in to your IBM Cloud account.
- Navigate to the Cloudant page.
- Choose a name for your instance and click Create. You are then redirected to that Cloudant instance.
IBM Cloud IAM (OAuthAPIKey)
IBM Cloud Identity and Access Management (IAM) is OAuthAPIKey-based authentication.To authenticate to IBM Cloud, you need the API Key and the URL of the target Cloudant instance. The API key is exchanged for an IAM access token, which is then used to authorize requests.
Creating Service Credentials
You can obtain the ApiKey and URL connection properties together when creating service credentials for the instance.To create an IBM Cloudant service credential:
- Log in to the IBM Cloud dashboard.
- Navigate to the Menu icon > Resource List, and open your IBM Cloudant service instance.
- In the menu, click Service credentials.
- Click New credential. Cloudant displays a Add new credential window.
- Enter a name for the new credential.
- Click Add. Your credentials are added to the Service credentials table.
- Click Actions > View credentials.
- Extract the values for ApiKey and URL from the JSON service credential blob.
Save this information for future reference.
Authenticating to Cloudant with OAuthAPIKey
To authenticate to IBM Cloud, set the following connection properties:- AuthScheme: OAuthAPIKey.
- ApiKey: The API key used to authenticate with IBM Cloud IAM.
- URL: The URL of the target Cloudant instance.
- For example, https://0c9d3837-8304-4aab-a65a-648169970943-bluemix.cloudantnosqldb.appdomain.cloud
IBM Cloudant Legacy (Basic)
To connect via IBM Cloudant Legacy, ensure that you have a valid IBM Cloudant service credential.To create an IBM Cloudant service credential:
- Log in to the IBM Cloud dashboard.
- Navigate to the Menu icon > Resource List, and open your IBM Cloudant service instance.
- In the menu, click Service credentials.
- Click New credential. Cloudant displays a Add new credential window.
- Enter a name for the new credential.
- Click Add. Your credentials are added to the Service credentials table.
- Click Actions > View credentials.
- Extract the values for User and Password from the JSON file.
To authenticate, set AuthScheme to Basic and use the values you just obtained to set the User and Password.
Authenticating to a Local Instance
Cloudant supports authenticating to data in local instances from version 1.1.0 and above.To authenticate to your local instance, set these parameters: