edit-icon download-icon

ApsaraDB for RDS

Last Updated: Mar 20, 2018

ApsaraDB for RDS (Relational Database Service) is a stable and reliable online database service that supports the elastic scaling function. ApsaraDB for RDS is based on the Apsara distributed system and high-performance storage of ephemeral SSD and supports MySQL, SQL Server, and PostgreSQL engines. ApsaraDB for RDS offers a complete set of solutions for backup, recovery, monitoring, migration, disaster recovery, and troubleshooting database operation and maintenance. For more information, see ApsaraDB for RDS.

This tutorial uses the CreateDBInstance API of ApsaraDB RDS to show you how to use Alibaba Cloud Java SDK to create an ApsaraDB for RDS instance.

Note: Running the code in this example will create an ApsaraDB RDS instance and generate fees.

  1. import java.util.UUID;
  2. import com.aliyuncs.DefaultAcsClient;
  3. import com.aliyuncs.IAcsClient;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.exceptions.ServerException;
  6. import com.aliyuncs.profile.DefaultProfile;
  7. import com.aliyuncs.rds.model.v20140815.CreateDBInstanceRequest;
  8. import com.aliyuncs.rds.model.v20140815.CreateDBInstanceResponse;
  9. public class Demo {
  10. public static void main(String[] args) {
  11. // Create and initialize the DefaultAcsClient instance
  12. DefaultProfile profile = DefaultProfile.getProfile(
  13. "<your-region-id>", // Your region ID
  14. "<your-access-key-id>", // Your AccessKey ID
  15. "<your-access-key-secret>"); // Your AccessKey Secret
  16. IAcsClient client = new DefaultAcsClient(profile);
  17. // Create a request and set parameters
  18. CreateDBInstanceRequest request = new CreateDBInstanceRequest();
  19. request.setEngine("MySQL");
  20. request.setEngineVersion("5.7");
  21. request.setDBInstanceClass("mysql.n1.micro.1");
  22. request.setDBInstanceStorage(20);
  23. request.setDBInstanceNetType("Intranet");
  24. request.setSecurityIPList("0.0.0.0/0");
  25. request.setPayType("Postpaid");
  26. request.setDBInstanceDescription("MyRds");
  27. request.setClientToken(UUID.randomUUID().toString());
  28. // Initiate the request and handle the response or exceptions
  29. CreateDBInstanceResponse response;
  30. try {
  31. response = client.getAcsResponse(request);
  32. String dbInstanceId = response.getDBInstanceId();
  33. System.out.println("Create dbInstance success, instanceId = " + dbInstanceId);
  34. } catch (ServerException e) {
  35. e.printStackTrace();
  36. } catch (ClientException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
Thank you! We've received your feedback.