Establishing a Connection
Creating a JDBC Data Source
You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for Cosmos DB consists of three basic steps:
- Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
- Provide the driver class. For example:
- Provide the JDBC URL. For example:
jdbc:cosmosdb:AccountEndpoint=myAccountEndpoint;AccountKey=myAccountKey; or jdbc:cdata:cosmosdb:AccountEndpoint=myAccountEndpoint;AccountKey=myAccountKey;
The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:cosmosdb:" or "jdbc:cdata:cosmosdb:" and can include any of the connection properties in name-value pairs separated with semicolons.
Connecting to Cosmos DB
Rest API (SQL API)
To obtain the connection string needed to connect to a Cosmos DB account using the SQL API, log in to the Azure Portal, select Azure Cosmos DB, and select your account. In the Settings section, click Connection String and set the following values:
- AccountEndpoint: The value should be the Cosmos DB account URL from the Keys blade of the Cosmos DB account.
- AccountKey: In the Azure portal, navigate to the Cosmos DB service and select your Azure Cosmos DB account. From the resource menu, go to the Keys page. Find the PRIMARY KEY value and set Token to this value.