如果表存储中不存在java Azure创建表



为什么在尝试将表创建到表存储时会出现以下错误:

com.microsoft.azure.storage.StorageException:确定网址:com.microsoft.azure.StorageException.translateException(StorageException.java:87(网址:com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:209(网址:com.microsoft.azure.storage.table.QueryTableOperation.performRetrieve(QueryTableOperation.java:178(网址:com.microsoft.azure.storage.table.TableOperation.execute(TableOperation.java:694(位于com.microsoft.azure.storage.table.CloudTable.exists(CloudTable.java:888(网址:com.microsoft.azure.storage.table.CloudTable.createIfNotExists(CloudTable.java:290(网址:com.microsoft.azure.storage.table.CloudTable.createIfNotExists(CloudTable.java:265(位于.dela.gdprvult.test.StorageTestClient.getTableByName(StorageTestClient.ggroovy:25(位于.dela.gdprvaum.logging.entity.ActionLogSystemSpec.getActionLogFromTableByPartitionAndRowKey(ActionLogSystemSpecgroovy:114(在be.dela.gdprvault.logging.entity.ActionLogSystemSpec.应该将ActionLog实体保存到表存储中(ActionLogSystemSpec.groovy:96(导致原因:java.lang.NullPointerException网址:com.microsoft.azure.storage.table.TableDeserializer.parseJsonEntity(TableDeserialize.java:290(网址:com.microsoft.azure.storage.table.TableDeserializer.parseSingleOpResponse(TableDeserialize.java:203(网址:com.microsoft.azure.storage.table.QueryTableOperation.parseResponse(QueryTableOperation.java:143(网址:com.microsoft.azure.storage.table.QueryTableOperation$1.postProcessResponse(QueryTableOperation.java:236(网址:com.microsoft.azure.storage.table.QueryTableOperation$1.postProcessResponse(QueryTableOperation.java:193(网址:com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:155(…还有8个

docer-compose
azure-blob-storage:
image: arafato/azurite
ports:
- "10000:10000"
- "10002:10002"
volumes:
- data-volume:/opt/azurite/folder
CloudTable table = tableClient.getTableReference(tableName)
table.createIfNotExists() -- there is error

我是根据文章写的https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-java

我试图重现您的异常,但失败了。您可以使用Fiddler来捕获java代码的请求和响应,以检查状态代码和错误详细信息。

你可以参考我的工作代码:

import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.table.*;
public class CreateTableTest {
public static final String storageConnectionString =
"DefaultEndpointsProtocol=https;" +
"AccountName=***;" +
"AccountKey=***;" +
"TableEndpoint=https://***.table.cosmosdb.azure.com:443/;" ;
public static void main(String[] args) {
try
{
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount =
CloudStorageAccount.parse(storageConnectionString);
// Create the table client.
CloudTableClient tableClient = storageAccount.createCloudTableClient();
// Create the table if it doesn't exist.
String tableName = "people";
CloudTable cloudTable = tableClient.getTableReference(tableName);
cloudTable.createIfNotExists();
System.out.println("Create Success...");
}
catch (Exception e)
{
// Output the stack trace.
e.printStackTrace();
}
}
}

我的sdk版本是:

<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.0.0</version>
</dependency>

最新更新