Azure Data Tables Java

by microsoft354361d83247MITListed Oct 8, 2026Updated Oct 8, 2026

Build table storage applications with Azure Tables SDK for Java. Use when working with Azure Table Storage or Cosmos DB Table API for NoSQL key-value data, schemaless storage, or structured data at scale.

FeaturedInstructions onlySoftware Development
AI-generated overview

Guides Java developers in building Azure Table Storage and Cosmos DB Table API applications with the Azure Tables SDK.

What it does
This skill provides reference instructions and code patterns for using the Azure Tables SDK for Java. It covers client creation with connection strings, shared keys, SAS tokens, and DefaultAzureCredential, plus table and entity CRUD, OData filtering, batch transactions, typed entities, and error handling. It produces guidance and example code rather than executable scripts.
When to use it
Use it when writing Java applications that store schemaless key-value or structured data in Azure Table Storage or the Cosmos DB Table API. It is suited to tasks involving partition and row keys, table entity operations, or querying tables with OData filters.
Requirements
Requires the com.azure:azure-data-tables Java package and an Azure Storage or Cosmos DB Table API account. Credentials such as a connection string, account key, SAS token, or Entra ID identity are needed, along with network access to the service endpoint. No scripts are included.

Azure Tables SDK for Java

Build table storage applications using the Azure Tables SDK for Java. Works with both Azure Table Storage and Cosmos DB Table API.

Installation

xml
<dependency>  <groupId>com.azure</groupId>  <artifactId>azure-data-tables</artifactId>  <version>12.6.0-beta.1</version></dependency>

Client Creation

With Connection String

java
import com.azure.data.tables.TableServiceClient;import com.azure.data.tables.TableServiceClientBuilder;import com.azure.data.tables.TableClient;
TableServiceClient serviceClient = new TableServiceClientBuilder()    .connectionString("<your-connection-string>")    .buildClient();

With Shared Key

java
import com.azure.core.credential.AzureNamedKeyCredential;
AzureNamedKeyCredential credential = new AzureNamedKeyCredential(    "<account-name>",    "<account-key>");
TableServiceClient serviceClient = new TableServiceClientBuilder()    .endpoint("<your-table-account-url>")    .credential(credential)    .buildClient();

With SAS Token

java
TableServiceClient serviceClient = new TableServiceClientBuilder()    .endpoint("<your-table-account-url>")    .sasToken("<sas-token>")    .buildClient();

With DefaultAzureCredential (Storage only)

java
import com.azure.core.credential.TokenCredential;import com.azure.identity.AzureIdentityEnvVars;import com.azure.identity.DefaultAzureCredentialBuilder;import com.azure.identity.ManagedIdentityCredentialBuilder;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>TokenCredential credential = new DefaultAzureCredentialBuilder()    .requireEnvVars(AzureIdentityEnvVars.AZURE_TOKEN_CREDENTIALS)    .build();// Or use a specific credential directly in production:// See https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes// TokenCredential credential = new ManagedIdentityCredentialBuilder().build();
TableServiceClient serviceClient = new TableServiceClientBuilder()    .endpoint("<your-table-account-url>")    .credential(credential)    .buildClient();

Key Concepts

  • TableServiceClient: Manage tables (create, list, delete)
  • TableClient: Manage entities within a table (CRUD)
  • Partition Key: Groups entities for efficient queries
  • Row Key: Unique identifier within a partition
  • Entity: A row with up to 252 properties (1MB Storage, 2MB Cosmos)

Core Patterns

Create Table

java
// Create table (throws if exists)TableClient tableClient = serviceClient.createTable("mytable");
// Create if not exists (no exception)TableClient tableClient = serviceClient.createTableIfNotExists("mytable");

Get Table Client

java
// From service clientTableClient tableClient = serviceClient.getTableClient("mytable");
// Direct constructionTableClient tableClient = new TableClientBuilder()    .connectionString("<connection-string>")    .tableName("mytable")    .buildClient();

Create Entity

java
import com.azure.data.tables.models.TableEntity;
TableEntity entity = new TableEntity("partitionKey", "rowKey")    .addProperty("Name", "Product A")    .addProperty("Price", 29.99)    .addProperty("Quantity", 100)    .addProperty("IsAvailable", true);
tableClient.createEntity(entity);

Get Entity

java
TableEntity entity = tableClient.getEntity("partitionKey", "rowKey");
String name = (String) entity.getProperty("Name");Double price = (Double) entity.getProperty("Price");System.out.printf("Product: %s, Price: %.2f%n", name, price);

Update Entity

java
import com.azure.data.tables.models.TableEntityUpdateMode;
// Merge (update only specified properties)TableEntity updateEntity = new TableEntity("partitionKey", "rowKey")    .addProperty("Price", 24.99);tableClient.updateEntity(updateEntity, TableEntityUpdateMode.MERGE);
// Replace (replace entire entity)TableEntity replaceEntity = new TableEntity("partitionKey", "rowKey")    .addProperty("Name", "Product A Updated")    .addProperty("Price", 24.99)    .addProperty("Quantity", 150);tableClient.updateEntity(replaceEntity, TableEntityUpdateMode.REPLACE);

Upsert Entity

java
// Insert or update (merge mode)tableClient.upsertEntity(entity, TableEntityUpdateMode.MERGE);
// Insert or replacetableClient.upsertEntity(entity, TableEntityUpdateMode.REPLACE);

Delete Entity

java
tableClient.deleteEntity("partitionKey", "rowKey");

List Entities

java
import com.azure.data.tables.models.ListEntitiesOptions;
// List all entitiesfor (TableEntity entity : tableClient.listEntities()) {    System.out.printf("%s - %s%n",        entity.getPartitionKey(),        entity.getRowKey());}
// With filtering and selectionListEntitiesOptions options = new ListEntitiesOptions()    .setFilter("PartitionKey eq 'sales'")    .setSelect("Name", "Price");
for (TableEntity entity : tableClient.listEntities(options, null, null)) {    System.out.printf("%s: %.2f%n",        entity.getProperty("Name"),        entity.getProperty("Price"));}

Query with OData Filter

java
// Filter by partition keyListEntitiesOptions options = new ListEntitiesOptions()    .setFilter("PartitionKey eq 'electronics'");
// Filter with multiple conditionsoptions.setFilter("PartitionKey eq 'electronics' and Price gt 100");
// Filter with comparison operatorsoptions.setFilter("Quantity ge 10 and Quantity le 100");
// Top N resultsoptions.setTop(10);
for (TableEntity entity : tableClient.listEntities(options, null, null)) {    System.out.println(entity.getRowKey());}

Batch Operations (Transactions)

java
import com.azure.data.tables.models.TableTransactionAction;import com.azure.data.tables.models.TableTransactionActionType;import java.util.Arrays;
// All entities must have same partition keyList<TableTransactionAction> actions = Arrays.asList(    new TableTransactionAction(        TableTransactionActionType.CREATE,        new TableEntity("batch", "row1").addProperty("Name", "Item 1")),    new TableTransactionAction(        TableTransactionActionType.CREATE,        new TableEntity("batch", "row2").addProperty("Name", "Item 2")),    new TableTransactionAction(        TableTransactionActionType.UPSERT_MERGE,        new TableEntity("batch", "row3").addProperty("Name", "Item 3")));
tableClient.submitTransaction(actions);

List Tables

java
import com.azure.data.tables.models.TableItem;import com.azure.data.tables.models.ListTablesOptions;
// List all tablesfor (TableItem table : serviceClient.listTables()) {    System.out.println(table.getName());}
// Filter tablesListTablesOptions options = new ListTablesOptions()    .setFilter("TableName eq 'mytable'");
for (TableItem table : serviceClient.listTables(options, null, null)) {    System.out.println(table.getName());}

Delete Table

java
serviceClient.deleteTable("mytable");

Typed Entities

java
public class Product implements TableEntity {    private String partitionKey;    private String rowKey;    private OffsetDateTime timestamp;    private String eTag;    private String name;    private double price;        // Getters and setters for all fields    @Override    public String getPartitionKey() { return partitionKey; }    @Override    public void setPartitionKey(String partitionKey) { this.partitionKey = partitionKey; }    @Override    public String getRowKey() { return rowKey; }    @Override    public void setRowKey(String rowKey) { this.rowKey = rowKey; }    // ... other getters/setters        public String getName() { return name; }    public void setName(String name) { this.name = name; }    public double getPrice() { return price; }    public void setPrice(double price) { this.price = price; }}
// UsageProduct product = new Product();product.setPartitionKey("electronics");product.setRowKey("laptop-001");product.setName("Laptop");product.setPrice(999.99);
tableClient.createEntity(product);

Error Handling

java
import com.azure.data.tables.models.TableServiceException;
try {    tableClient.createEntity(entity);} catch (TableServiceException e) {    System.out.println("Status: " + e.getResponse().getStatusCode());    System.out.println("Error: " + e.getMessage());    // 409 = Conflict (entity exists)    // 404 = Not Found}

Environment Variables

bash
# Storage AccountAZURE_TABLES_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=...  # Alternative to Entra ID authAZURE_TABLES_ENDPOINT=https://<account>.table.core.windows.net  # Required for all auth methodsAZURE_TOKEN_CREDENTIALS=prod  # Required only if DefaultAzureCredential is used in production
# Cosmos DB Table APICOSMOS_TABLE_ENDPOINT=https://<account>.table.cosmosdb.azure.com  # Alternative endpoint for Cosmos DB Table API

Best Practices

  1. Partition Key Design: Choose keys that distribute load evenly
  2. Batch Operations: Use transactions for atomic multi-entity updates
  3. Query Optimization: Always filter by PartitionKey when possible
  4. Select Projection: Only select needed properties for performance
  5. Entity Size: Keep entities under 1MB (Storage) or 2MB (Cosmos)

Trigger Phrases

  • "Azure Tables Java"
  • "table storage SDK"
  • "Cosmos DB Table API"
  • "NoSQL key-value storage"
  • "partition key row key"
  • "table entity CRUD"

Source and attribution

Source:microsoft/skillsin.github/plugins/azure-sdk-java/skills/azure-data-tables-javaat commit354361d

License: MIT

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal