Shaun Barney
Shaun Barney

Reputation: 738

Microsoft Azure Table Storage: CloudTable() error no suggestions available

I'm using the Azure table storage from java, following the tutorial here. I'm successfully able to create a table, add an entity, retrieve an entity and delete an entity. However, I've got this method to delete a table:

public void deleteTable(String tableName) {
    try {
        CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
        CloudTableClient tableClient = storageAccount.createCloudTableClient();

        // Delete the table and all its data if it exists.
        CloudTable cloudTable = new CloudTable(tableName, tableClient);

        cloudTable.deleteIfExists();
    } catch (Exception e) {
        System.out.println("Error in deleting");
        e.printStackTrace();
    }
}

In this method I am getting an error on this line

CloudTable cloudTable = new CloudTable(tableName, tableClient);

which has no suggestions available within eclipse only the following markers:

Multiple markers at this line

  • The constructor CloudTable(String, CloudTableClient) is not visible
  • The constructor CloudTable(String, CloudTableClient) is not visible

Any help would be greatly appreciated.

Upvotes: 2

Views: 391

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136266

If you look at CloudTable constructors here, you will notice that the code you're using is not a valid one. It is possible that the SDK got upgraded however the code sample isn't. I would suggest using getTableReference method on CloudTableClient to get an instance of CloudTable:

try
{
    // Retrieve storage account from connection-string.
    CloudStorageAccount storageAccount =
        CloudStorageAccount.parse(storageConnectionString);

    // Create the table client.
    CloudTableClient tableClient = storageAccount.createCloudTableClient();

    // Delete the table and all its data if it exists.
    CloudTable cloudTable = tableClient.getTableReference("people");
    cloudTable.deleteIfExists();
}
catch (Exception e)
{
    // Output the stack trace.
    e.printStackTrace();
}

Upvotes: 1

Related Questions