Get a database admin (Java)
The Data API clients use the Database Admin class to perform administrative operations, like managing keyspaces, within a specific database.
To perform administrative actions outside of a specific database, see Get an Astra DB admin (Java) instead.
The Database Admin class name varies by client.
The Java client uses DatabaseAdmin.
|
You need an application token with permission to interact with the target database, such as the Database Administrator role. For more information, see Get endpoint and token. |
Result
Returns a DatabaseAdmin object that can perform administrative actions on the specified database.
Parameters
Use the getDatabaseAdmin method from the com.datastax.astra.client.Database class.
Method signature
DatabaseAdmin getDatabaseAdmin()
DatabaseAdmin getDatabaseAdmin(String superUserToken)
DatabaseAdmin getDatabaseAdmin(AdminOptions adminOptions)
| Name | Type | Summary |
|---|---|---|
|
|
Optional. The token used by the resulting admin object. The token should have sufficient permissions to perform the desired downstream operations. If not specified, the resulting object will use the token used by the object that called this method. |
|
Optional. A specification of options to override the inherited defaults. Use this to customize the interaction of the client with the database admin. For example, you can change the default timeouts. |
Alternatively, use the getDatabaseAdmin method from the com.datastax.astra.client.admin.AstraDBAdmin class.
Alternative method signature and parameters
AstraDBDatabaseAdmin getDatabaseAdmin(UUID databaseId)
| Name | Type | Summary |
|---|---|---|
|
|
The ID of the database for which to create an admin object. |
Examples
The following examples demonstrate how to get a database admin object.
Get a database admin from a database
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.admin.DatabaseAdmin;
import com.datastax.astra.client.databases.Database;
public class Example {
public static void main(String[] args) {
// Get a database object
Database database = new DataAPIClient("APPLICATION_TOKEN").getDatabase("API_ENDPOINT");
// Get a database admin object
DatabaseAdmin databaseAdmin = database.getDatabaseAdmin();
}
}
Get a database admin from an admin
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.admin.AstraDBAdmin;
import com.datastax.astra.client.admin.AstraDBDatabaseAdmin;
public class Example {
public static void main(String[] args) {
// Get an admin object
DataAPIClient client = new DataAPIClient("APPLICATION_TOKEN");
AstraDBAdmin admin = client.getAdmin();
// Get a database admin object
AstraDBDatabaseAdmin databaseAdmin = admin.getDatabaseAdmin("API_ENDPOINT");
}
}
Client reference
For more information, see the client reference.