All Products
Search
Document Center

Use the DBS Java SDK through Maven dependencies

Last Updated: Mar 24, 2020

The DBS SDK for Java includes two core kits: aliyun-java-sdk-core and aliyun-java-sdk-dbs. The aliyun-java-sdk-core kit automatically routes requests to the DBS endpoint. The aliyun-java-sdk-dbs kit includes the related classes of all DBS features. You can use the latest versions in the current Maven repository as the versions of these two kits.

Maven configuration

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-dbs</artifactId>
    <version>1.0.11</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.4.0</version>
</dependency>

Client initialization

// Use the profile to declare the AccessKey ID, AccessKey secret, and the region of the DBS instance.
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "accsessKeyId", "accessSecret");
// Use the profile to initialize a client object.
IAcsClient client = new DefaultAcsClient(profile);

Example of calling the CreateBackupPlan operation

// Declare a request object.
CreateBackupPlanRequest req = new CreateBackupPlanRequest();
// Set the request parameters. For example, set the Region, DatabaseType,
// InstanceClass, BackupMethod, Period, and UsedTime parameters for calling the CreateBackupPlan operation.
req.setRegion("cn-hangzhou");
req.setDatabaseType("MySQL");
req.setInstanceClass("small");
req.setBackupMethod("logical");
req.setPeriod("Month");
req.setUsedTime(1);
// Receive the response to the request through the client.
CreateBackupPlanResponse response = client.getAcsResponse(req);
// Call the GET method in the response to retrieve the returned parameter values, for example, the backup schedule ID.
String backupPlanId=response.getBackupPlanId();