Cosmos db connect with java code --->>> How to ??

Ey 1 Reputation point

I am trying to connect to cosmos db with java code (Uisng intellij)
in order to validate some field exist or not.

can someone gove me the simplest sample code for doing connection and quick sql query for pull some data ?


Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,469 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Oury Ba-MSFT 16,891 Reputation points Microsoft Employee

    Hi @Ey Thank you for posting your question.

    Please try the below samples using either an IDE (Eclipse, IntelliJ, or VSCODE) or from the command line using Maven.

    These environment variables must be set
    ACCOUNT_HOST=your account hostname;ACCOUNT_KEY=your account primary key (

    / Create sync client
    // <CreateSyncClient>
    client = new CosmosClientBuilder()

    Please refer to the below link for java Quickstart examples.