This topic describes how to use Data Transmission Service (DTS) SDK for Java and provides examples for your reference.
Prerequisites
- An AccessKey pair is created. For more information, see Obtain an AccessKey pair.
Note To protect the AccessKey pair of your Alibaba Cloud account, we recommend that you create a RAM user, grant the RAM user the permissions to access DTS, and then use the AccessKey pair of the RAM user to call DTS SDK for Java. For more information, see Control access to resources by using RAM users.
- The SDK installation package of DTS is downloaded. For more information, see Download SDKs.
Install the SDK
You can install Alibaba Cloud SDK for Java by adding Maven dependencies or by importing JAR files. For more information, see Dependencies.
Note
- You can view the Maven dependencies of DTS in SDK Center.
- If you choose to download the SDK installation package by adding Maven dependencies, we recommend that you use the latest version of the SDK.
Procedure
Sample request
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.dts.model.v20180801.*;
public class CreateMigrationJob {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "********", "********");
IAcsClient client = new DefaultAcsClient(profile);
CreateMigrationJobRequest request = new CreateMigrationJobRequest();
request.setRegionId("cn-hangzhou");
request.setRegion("cn-hangzhou");
request.setMigrationJobClass("large");
try {
CreateMigrationJobResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
Sample response
{"MigrationJobId":"dts********","Success":true}
References
- Perform online debugging and generate SDK sample code.
Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to search for API operations, call API operations, and dynamically generate SDK sample code.
- For more information about the SDK, see Get started with Alibaba Cloud Classic SDK for Java.