This topic describes how to install and use RDS SDK for Java. RDS SDK for Java allows you to access your ApsaraDB for RDS instance without the need for complex programming.

Background information

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.

Prerequisites

  • An AccessKey pair is created. For more information, see Create an AccessKey.
    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 ApsaraDB for RDS instances, and then use the AccessKey pair of the RAM user to call RDS SDK for Java. For more information, see Implement access control by using RAM.
  • Version 1.6 or later of Java is installed.

Install RDS SDK for Java

  1. Visit the Alibaba Cloud SDK for Java page at GitHub.
  2. Download the RDS SDK for Java package and install the SDK by following the instructions provided in the README file.

Procedure

  1. Configure the following parameters:
    IClientProfile profile
                 = DefaultProfile.getProfile(
            "regonId",    // The ID of the region where your RDS instance resides.
            "accessKeyId",    // The AccessKey ID of your RAM user.
            "accessKeySecret"    // The AccessKey secret of your RAM user.
    );
  2. Configure the endpoint that is used to connect to your RDS instance.
    DefaultProfile.addEndpoint(
            "endpointName",    // The name of the endpoint.
            "regionId",    // The ID of the region where your RDS instance resides.
            "product(Rds)",    // The product code of ApsaraDB for RDS. Enter Rds.
            "domain(endpoint)"    // The endpoint.
    );
    Note For more information, see Request structure.
  3. Configure the parameters that are used to initialize the request.

    For example, configure the following parameters to initialize the request that is used to call the DescribeDBInstanceAttribute operation:

    DescribeDBInstanceAttributeRequest request = new  DescribeDBInstanceAttributeRequest();
          request.setDBInstanceId("rm-bp1xxxxxxx");
  4. Initiate the AcsClient.
    IAcsClient client = new DefaultAcsClient(profile);
  5. View the response.
    DescribeDBInstanceAttributeResponse response =client.getAcsResponse(request);

Examples

Sample request:

IClientProfile profile
                = DefaultProfile.getProfile("cn-hangzhou","Akxxxxx",
                "Skxxxxx");
        DefaultProfile.addEndpoint("ap-southeast-5",
                "ap-southeast-5", "Rds", "rds.ap-southeast-5.aliyuncs.com");
        DescribeDBInstanceAttributeRequest request = new DescribeDBInstanceAttributeRequest();
        request.setDBInstanceId("rm-bp1oxxxxxxx");
        IAcsClient client = new DefaultAcsClient(profile);
        try {
            DescribeDBInstanceAttributeResponse response = client.getAcsResponse(request);
                System.out.println(JSON.toJSONString(response));
        }catch (ServerException e) {
            e.printStackTrace();

        } catch (ClientException e) {
            e.printStackTrace();
        }

Sample response:

{"items":
    [{"accountMaxQuantity":1,
      "accountType":"Normal",
      "availabilityValue":"100.0%",
      "category":"Basic",
      "connectionMode":"Standard",
      "connectionString":"rm-bp1oxxxxxxx.mysql.rds.aliyuncs.com",
      "creationTime":"2018-05-15T02:48:10Z",
      "dBInstanceCPU":"2",
      "dBInstanceClass":"mysql.n2.medium.1",
      "dBInstanceClassType":"x",
      "dBInstanceId":"rm-bp1oxxxxxxx",
      "dBInstanceMemory":4096,
      "dBInstanceNetType":"Intranet",
      "dBInstanceStatus":"Running",
      "dBInstanceStorage":20,
      "dBInstanceType":"Primary",
      "dBMaxQuantity":0,
      "engine":"MySQL",
      "engineVersion":"5.7",
      "expireTime":"",
      "insId":1,
      "instanceNetworkType":"VPC",
      "lockMode":"Unlock",
      "maintainTime":"18:00Z-22:00Z",
      "maxConnections":4000,
      "maxIOPS":600,
      "payType":"Postpaid",
      "port":"3306",
      "readOnlyDBInstanceIds":[],
      "regionId":"cn-hangzhou",
      "resourceGroupId":"rg-acfxxxxxxx",
      "securityIPList":"",
      "supportUpgradeAccountType":"Yes",
      "vSwitchId":"vsw-bp1xxxxxxx",
      "vpcId":"vpc-bp1xxxxxxx",
      "zoneId":"cn-hangzhou-f"}],
    "requestId":"2E656746-432A-4EA9-82BC-B89F1A26AE8B"}