Skip to content

Latest commit

 

History

History
65 lines (48 loc) · 2.33 KB

File metadata and controls

65 lines (48 loc) · 2.33 KB
ms.data ms.service author ms.topic title ms.devlang ms.author description ms.date
08/27/2022
cosmosdb
kushagraThapar
reference
Azure Cosmos DB SDK for Java
java
kuthapar
Reference for Azure Cosmos DB SDK for Java
07/08/2022

Azure Cosmos DB libraries for Java

Overview

Store and query key-value, JSON document, graph, and columnar data in a globally distributed database with Azure Cosmos DB.

To get started with Azure Cosmos DB, see Azure Cosmos DB: Build an API app with Java and the Azure portal.

Client library

Connect to Azure Cosmos DB using the SQL API client library to work with JSON data with SQL query syntax.

Add a dependency to your Maven pom.xml file to use the Cosmos DB client library in your project.

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-documentdb</artifactId>
    <version>1.12.0</version>
</dependency>

Example

Select matching JSON documents in Cosmos DB using SQL query syntax.

DocumentClient client = new DocumentClient("https://contoso.documents.azure.com:443",
                "contosoCosmosDBKey", 
                new ConnectionPolicy(),
                ConsistencyLevel.Session);

List<Document> results = client.queryDocuments("dbs/" + DATABASE_ID + "/colls/" + COLLECTION_ID,
        "SELECT * FROM myCollection WHERE myCollection.email = 'allen [at] contoso.com'",
        null)
    .getQueryIterable()
    .toList();

[!div class="nextstepaction"] Explore the Client APIs

Samples

Develop a Java app using Azure Cosmos DB MongoDB API
Develop a Java app using Azure Cosmos DB Graph API
Develop a Java app using Azure Cosmos DB SQL API

Explore more sample Java code for Azure Cosmos DB you can use in your apps.