| GitHub Repository | Product Reference |
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesDeleteRequest request =
SqlDatabasesDeleteRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
Operation response = sqlDatabasesServiceClient.delete(request);
}
Note: close() needs to be called on the SqlDatabasesServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
Delete |
Deletes a database from a Cloud SQL instance. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
Get |
Retrieves a resource containing information about a database inside a Cloud SQL instance. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
Insert |
Inserts a resource containing information about a database inside a Cloud SQL instance. **Note:** You can't modify the default character set and collation. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
List |
Lists databases in the specified Cloud SQL instance. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
Patch |
Partially updates a resource containing information about a database inside a Cloud SQL instance. This method supports patch semantics. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
Update |
Updates a resource containing information about a database inside a Cloud SQL instance. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SqlDatabasesServiceSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
SqlDatabasesServiceSettings sqlDatabasesServiceSettings =
SqlDatabasesServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SqlDatabasesServiceClient sqlDatabasesServiceClient =
SqlDatabasesServiceClient.create(sqlDatabasesServiceSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
SqlDatabasesServiceSettings sqlDatabasesServiceSettings =
SqlDatabasesServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
SqlDatabasesServiceClient sqlDatabasesServiceClient =
SqlDatabasesServiceClient.create(sqlDatabasesServiceSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
SqlDatabasesServiceSettings sqlDatabasesServiceSettings =
SqlDatabasesServiceSettings.newHttpJsonBuilder().build();
SqlDatabasesServiceClient sqlDatabasesServiceClient =
SqlDatabasesServiceClient.create(sqlDatabasesServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Static Methods
create()
public static final SqlDatabasesServiceClient create()Constructs an instance of SqlDatabasesServiceClient with default settings.
| Returns | |
|---|---|
| Type | Description |
SqlDatabasesServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
create(SqlDatabasesServiceSettings settings)
public static final SqlDatabasesServiceClient create(SqlDatabasesServiceSettings settings)Constructs an instance of SqlDatabasesServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
| Parameter | |
|---|---|
| Name | Description |
settings |
SqlDatabasesServiceSettings |
| Returns | |
|---|---|
| Type | Description |
SqlDatabasesServiceClient |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
create(SqlDatabasesServiceStub stub)
public static final SqlDatabasesServiceClient create(SqlDatabasesServiceStub stub)Constructs an instance of SqlDatabasesServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(SqlDatabasesServiceSettings).
| Parameter | |
|---|---|
| Name | Description |
stub |
SqlDatabasesServiceStub |
| Returns | |
|---|---|
| Type | Description |
SqlDatabasesServiceClient |
|
Constructors
SqlDatabasesServiceClient(SqlDatabasesServiceSettings settings)
protected SqlDatabasesServiceClient(SqlDatabasesServiceSettings settings)Constructs an instance of SqlDatabasesServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
| Parameter | |
|---|---|
| Name | Description |
settings |
SqlDatabasesServiceSettings |
SqlDatabasesServiceClient(SqlDatabasesServiceStub stub)
protected SqlDatabasesServiceClient(SqlDatabasesServiceStub stub)| Parameter | |
|---|---|
| Name | Description |
stub |
SqlDatabasesServiceStub |
Methods
awaitTermination(long duration, TimeUnit unit)
public boolean awaitTermination(long duration, TimeUnit unit)| Parameters | |
|---|---|
| Name | Description |
duration |
long |
unit |
TimeUnit |
| Returns | |
|---|---|
| Type | Description |
boolean |
|
| Exceptions | |
|---|---|
| Type | Description |
InterruptedException |
|
close()
public final void close()delete(SqlDatabasesDeleteRequest request)
public final Operation delete(SqlDatabasesDeleteRequest request)Deletes a database from a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesDeleteRequest request =
SqlDatabasesDeleteRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
Operation response = sqlDatabasesServiceClient.delete(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlDatabasesDeleteRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Operation |
|
deleteCallable()
public final UnaryCallable<SqlDatabasesDeleteRequest,Operation> deleteCallable()Deletes a database from a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesDeleteRequest request =
SqlDatabasesDeleteRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
ApiFuture<Operation> future = sqlDatabasesServiceClient.deleteCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlDatabasesDeleteRequest,Operation> |
|
get(SqlDatabasesGetRequest request)
public final Database get(SqlDatabasesGetRequest request)Retrieves a resource containing information about a database inside a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesGetRequest request =
SqlDatabasesGetRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
Database response = sqlDatabasesServiceClient.get(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlDatabasesGetRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Database |
|
getCallable()
public final UnaryCallable<SqlDatabasesGetRequest,Database> getCallable()Retrieves a resource containing information about a database inside a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesGetRequest request =
SqlDatabasesGetRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
ApiFuture<Database> future = sqlDatabasesServiceClient.getCallable().futureCall(request);
// Do something.
Database response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlDatabasesGetRequest,Database> |
|
getSettings()
public final @Nullable SqlDatabasesServiceSettings getSettings()| Returns | |
|---|---|
| Type | Description |
@org.jspecify.annotations.Nullable com.google.cloud.sql.v1beta4.SqlDatabasesServiceSettings |
|
getStub()
public SqlDatabasesServiceStub getStub()| Returns | |
|---|---|
| Type | Description |
SqlDatabasesServiceStub |
|
insert(SqlDatabasesInsertRequest request)
public final Operation insert(SqlDatabasesInsertRequest request)Inserts a resource containing information about a database inside a Cloud SQL instance.
**Note:** You can't modify the default character set and collation.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesInsertRequest request =
SqlDatabasesInsertRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(Database.newBuilder().build())
.build();
Operation response = sqlDatabasesServiceClient.insert(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlDatabasesInsertRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Operation |
|
insertCallable()
public final UnaryCallable<SqlDatabasesInsertRequest,Operation> insertCallable()Inserts a resource containing information about a database inside a Cloud SQL instance.
**Note:** You can't modify the default character set and collation.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesInsertRequest request =
SqlDatabasesInsertRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(Database.newBuilder().build())
.build();
ApiFuture<Operation> future = sqlDatabasesServiceClient.insertCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlDatabasesInsertRequest,Operation> |
|
isShutdown()
public boolean isShutdown()| Returns | |
|---|---|
| Type | Description |
boolean |
|
isTerminated()
public boolean isTerminated()| Returns | |
|---|---|
| Type | Description |
boolean |
|
list(SqlDatabasesListRequest request)
public final DatabasesListResponse list(SqlDatabasesListRequest request)Lists databases in the specified Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesListRequest request =
SqlDatabasesListRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
DatabasesListResponse response = sqlDatabasesServiceClient.list(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlDatabasesListRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
DatabasesListResponse |
|
listCallable()
public final UnaryCallable<SqlDatabasesListRequest,DatabasesListResponse> listCallable()Lists databases in the specified Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesListRequest request =
SqlDatabasesListRequest.newBuilder()
.setInstance("instance555127957")
.setProject("project-309310695")
.build();
ApiFuture<DatabasesListResponse> future =
sqlDatabasesServiceClient.listCallable().futureCall(request);
// Do something.
DatabasesListResponse response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlDatabasesListRequest,DatabasesListResponse> |
|
patch(SqlDatabasesUpdateRequest request)
public final Operation patch(SqlDatabasesUpdateRequest request)Partially updates a resource containing information about a database inside a Cloud SQL instance. This method supports patch semantics.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesUpdateRequest request =
SqlDatabasesUpdateRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(Database.newBuilder().build())
.build();
Operation response = sqlDatabasesServiceClient.patch(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlDatabasesUpdateRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Operation |
|
patchCallable()
public final UnaryCallable<SqlDatabasesUpdateRequest,Operation> patchCallable()Partially updates a resource containing information about a database inside a Cloud SQL instance. This method supports patch semantics.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesUpdateRequest request =
SqlDatabasesUpdateRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(Database.newBuilder().build())
.build();
ApiFuture<Operation> future = sqlDatabasesServiceClient.patchCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlDatabasesUpdateRequest,Operation> |
|
shutdown()
public void shutdown()shutdownNow()
public void shutdownNow()update(SqlDatabasesUpdateRequest request)
public final Operation update(SqlDatabasesUpdateRequest request)Updates a resource containing information about a database inside a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesUpdateRequest request =
SqlDatabasesUpdateRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(Database.newBuilder().build())
.build();
Operation response = sqlDatabasesServiceClient.update(request);
}
| Parameter | |
|---|---|
| Name | Description |
request |
SqlDatabasesUpdateRequestThe request object containing all of the parameters for the API call. |
| Returns | |
|---|---|
| Type | Description |
Operation |
|
updateCallable()
public final UnaryCallable<SqlDatabasesUpdateRequest,Operation> updateCallable()Updates a resource containing information about a database inside a Cloud SQL instance.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (SqlDatabasesServiceClient sqlDatabasesServiceClient = SqlDatabasesServiceClient.create()) {
SqlDatabasesUpdateRequest request =
SqlDatabasesUpdateRequest.newBuilder()
.setDatabase("database1789464955")
.setInstance("instance555127957")
.setProject("project-309310695")
.setBody(Database.newBuilder().build())
.build();
ApiFuture<Operation> future = sqlDatabasesServiceClient.updateCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
| Returns | |
|---|---|
| Type | Description |
UnaryCallable<SqlDatabasesUpdateRequest,Operation> |
|