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.
Add this skill
npx mdskills install sickn33/azure-data-tables-javaComprehensive Java SDK reference with excellent examples but lacks agent-specific instructions
1---2name: azure-data-tables-java3description: 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.4package: com.azure:azure-data-tables5---67# Azure Tables SDK for Java89Build table storage applications using the Azure Tables SDK for Java. Works with both Azure Table Storage and Cosmos DB Table API.1011## Installation1213```xml14<dependency>15 <groupId>com.azure</groupId>16 <artifactId>azure-data-tables</artifactId>17 <version>12.6.0-beta.1</version>18</dependency>19```2021## Client Creation2223### With Connection String2425```java26import com.azure.data.tables.TableServiceClient;27import com.azure.data.tables.TableServiceClientBuilder;28import com.azure.data.tables.TableClient;2930TableServiceClient serviceClient = new TableServiceClientBuilder()31 .connectionString("<your-connection-string>")32 .buildClient();33```3435### With Shared Key3637```java38import com.azure.core.credential.AzureNamedKeyCredential;3940AzureNamedKeyCredential credential = new AzureNamedKeyCredential(41 "<account-name>",42 "<account-key>");4344TableServiceClient serviceClient = new TableServiceClientBuilder()45 .endpoint("<your-table-account-url>")46 .credential(credential)47 .buildClient();48```4950### With SAS Token5152```java53TableServiceClient serviceClient = new TableServiceClientBuilder()54 .endpoint("<your-table-account-url>")55 .sasToken("<sas-token>")56 .buildClient();57```5859### With DefaultAzureCredential (Storage only)6061```java62import com.azure.identity.DefaultAzureCredentialBuilder;6364TableServiceClient serviceClient = new TableServiceClientBuilder()65 .endpoint("<your-table-account-url>")66 .credential(new DefaultAzureCredentialBuilder().build())67 .buildClient();68```6970## Key Concepts7172- **TableServiceClient**: Manage tables (create, list, delete)73- **TableClient**: Manage entities within a table (CRUD)74- **Partition Key**: Groups entities for efficient queries75- **Row Key**: Unique identifier within a partition76- **Entity**: A row with up to 252 properties (1MB Storage, 2MB Cosmos)7778## Core Patterns7980### Create Table8182```java83// Create table (throws if exists)84TableClient tableClient = serviceClient.createTable("mytable");8586// Create if not exists (no exception)87TableClient tableClient = serviceClient.createTableIfNotExists("mytable");88```8990### Get Table Client9192```java93// From service client94TableClient tableClient = serviceClient.getTableClient("mytable");9596// Direct construction97TableClient tableClient = new TableClientBuilder()98 .connectionString("<connection-string>")99 .tableName("mytable")100 .buildClient();101```102103### Create Entity104105```java106import com.azure.data.tables.models.TableEntity;107108TableEntity entity = new TableEntity("partitionKey", "rowKey")109 .addProperty("Name", "Product A")110 .addProperty("Price", 29.99)111 .addProperty("Quantity", 100)112 .addProperty("IsAvailable", true);113114tableClient.createEntity(entity);115```116117### Get Entity118119```java120TableEntity entity = tableClient.getEntity("partitionKey", "rowKey");121122String name = (String) entity.getProperty("Name");123Double price = (Double) entity.getProperty("Price");124System.out.printf("Product: %s, Price: %.2f%n", name, price);125```126127### Update Entity128129```java130import com.azure.data.tables.models.TableEntityUpdateMode;131132// Merge (update only specified properties)133TableEntity updateEntity = new TableEntity("partitionKey", "rowKey")134 .addProperty("Price", 24.99);135tableClient.updateEntity(updateEntity, TableEntityUpdateMode.MERGE);136137// Replace (replace entire entity)138TableEntity replaceEntity = new TableEntity("partitionKey", "rowKey")139 .addProperty("Name", "Product A Updated")140 .addProperty("Price", 24.99)141 .addProperty("Quantity", 150);142tableClient.updateEntity(replaceEntity, TableEntityUpdateMode.REPLACE);143```144145### Upsert Entity146147```java148// Insert or update (merge mode)149tableClient.upsertEntity(entity, TableEntityUpdateMode.MERGE);150151// Insert or replace152tableClient.upsertEntity(entity, TableEntityUpdateMode.REPLACE);153```154155### Delete Entity156157```java158tableClient.deleteEntity("partitionKey", "rowKey");159```160161### List Entities162163```java164import com.azure.data.tables.models.ListEntitiesOptions;165166// List all entities167for (TableEntity entity : tableClient.listEntities()) {168 System.out.printf("%s - %s%n",169 entity.getPartitionKey(),170 entity.getRowKey());171}172173// With filtering and selection174ListEntitiesOptions options = new ListEntitiesOptions()175 .setFilter("PartitionKey eq 'sales'")176 .setSelect("Name", "Price");177178for (TableEntity entity : tableClient.listEntities(options, null, null)) {179 System.out.printf("%s: %.2f%n",180 entity.getProperty("Name"),181 entity.getProperty("Price"));182}183```184185### Query with OData Filter186187```java188// Filter by partition key189ListEntitiesOptions options = new ListEntitiesOptions()190 .setFilter("PartitionKey eq 'electronics'");191192// Filter with multiple conditions193options.setFilter("PartitionKey eq 'electronics' and Price gt 100");194195// Filter with comparison operators196options.setFilter("Quantity ge 10 and Quantity le 100");197198// Top N results199options.setTop(10);200201for (TableEntity entity : tableClient.listEntities(options, null, null)) {202 System.out.println(entity.getRowKey());203}204```205206### Batch Operations (Transactions)207208```java209import com.azure.data.tables.models.TableTransactionAction;210import com.azure.data.tables.models.TableTransactionActionType;211import java.util.Arrays;212213// All entities must have same partition key214List<TableTransactionAction> actions = Arrays.asList(215 new TableTransactionAction(216 TableTransactionActionType.CREATE,217 new TableEntity("batch", "row1").addProperty("Name", "Item 1")),218 new TableTransactionAction(219 TableTransactionActionType.CREATE,220 new TableEntity("batch", "row2").addProperty("Name", "Item 2")),221 new TableTransactionAction(222 TableTransactionActionType.UPSERT_MERGE,223 new TableEntity("batch", "row3").addProperty("Name", "Item 3"))224);225226tableClient.submitTransaction(actions);227```228229### List Tables230231```java232import com.azure.data.tables.models.TableItem;233import com.azure.data.tables.models.ListTablesOptions;234235// List all tables236for (TableItem table : serviceClient.listTables()) {237 System.out.println(table.getName());238}239240// Filter tables241ListTablesOptions options = new ListTablesOptions()242 .setFilter("TableName eq 'mytable'");243244for (TableItem table : serviceClient.listTables(options, null, null)) {245 System.out.println(table.getName());246}247```248249### Delete Table250251```java252serviceClient.deleteTable("mytable");253```254255## Typed Entities256257```java258public class Product implements TableEntity {259 private String partitionKey;260 private String rowKey;261 private OffsetDateTime timestamp;262 private String eTag;263 private String name;264 private double price;265266 // Getters and setters for all fields267 @Override268 public String getPartitionKey() { return partitionKey; }269 @Override270 public void setPartitionKey(String partitionKey) { this.partitionKey = partitionKey; }271 @Override272 public String getRowKey() { return rowKey; }273 @Override274 public void setRowKey(String rowKey) { this.rowKey = rowKey; }275 // ... other getters/setters276277 public String getName() { return name; }278 public void setName(String name) { this.name = name; }279 public double getPrice() { return price; }280 public void setPrice(double price) { this.price = price; }281}282283// Usage284Product product = new Product();285product.setPartitionKey("electronics");286product.setRowKey("laptop-001");287product.setName("Laptop");288product.setPrice(999.99);289290tableClient.createEntity(product);291```292293## Error Handling294295```java296import com.azure.data.tables.models.TableServiceException;297298try {299 tableClient.createEntity(entity);300} catch (TableServiceException e) {301 System.out.println("Status: " + e.getResponse().getStatusCode());302 System.out.println("Error: " + e.getMessage());303 // 409 = Conflict (entity exists)304 // 404 = Not Found305}306```307308## Environment Variables309310```bash311# Storage Account312AZURE_TABLES_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=...313AZURE_TABLES_ENDPOINT=https://<account>.table.core.windows.net314315# Cosmos DB Table API316COSMOS_TABLE_ENDPOINT=https://<account>.table.cosmosdb.azure.com317```318319## Best Practices3203211. **Partition Key Design**: Choose keys that distribute load evenly3222. **Batch Operations**: Use transactions for atomic multi-entity updates3233. **Query Optimization**: Always filter by PartitionKey when possible3244. **Select Projection**: Only select needed properties for performance3255. **Entity Size**: Keep entities under 1MB (Storage) or 2MB (Cosmos)326327## Trigger Phrases328329- "Azure Tables Java"330- "table storage SDK"331- "Cosmos DB Table API"332- "NoSQL key-value storage"333- "partition key row key"334- "table entity CRUD"335
Full transparency — inspect the skill content before installing.