欢迎使用阿里云开发者工具套件(Alibaba Cloud SDK for Java)。Alibaba Cloud SDK for Java让您不用复杂编程即可访问云数据库RDS版。本教程介绍如何安装并开始使用Alibaba Cloud SDK for Java。

在线调试和生成SDK示例

OpenAPI Explorer提供在线调用云产品API、动态生成 SDK示例代码和快速检索接口等功能,能显著降低使用API的难度,推荐您使用。

前提条件

  • 使用Alibaba Cloud SDK for Java,您需要一个阿里云账号和访问密钥(AccessKey)。 请在阿里云控制台中的AccessKey管理页面创建和查看您的AccessKey,或联系您的系统管理员。
  • 安装Java环境。Alibaba Cloud SDK for Java要求使用JDK1.6或更高版本。

安装Alibaba Cloud SDK for Java

您可以通过添加Maven依赖或者导入Jar文件来安装RDS Java SDK,详细说明请参见安装Alibaba Cloud SDK for Java

说明 通过Maven下载SDK包时,请下载最新版本。

请求步骤

  1. 设置参数
    IClientProfile profile
                 = DefaultProfile.getProfile(
            "regonId",    // 地域ID
            "accessKeyId",    // RAM账号的AccessKey ID
            "accessKeySecret"    // RAM账号Access Key Secret
    );
  2. 设置域名
    DefaultProfile.addEndpoint(
            "endpointName",    // endpoint名称
            "regionId",    // 地域ID
            "product(Rds)",    // 产品编码,RDS的编码为Rds
            "domain(endpoint)"    // 接入地址,即域名
    );
    说明 RDS的域名请参见服务地址
  3. 初始化请求类设置请求参数

    以查询实例详情接口DescribeDBInstanceAttribute为例:

    DescribeDBInstanceAttributeRequest request = new  DescribeDBInstanceAttributeRequest();
          request.setDBInstanceId("rm-bp1xxxxxxx");
  4. 初始化客户端
    IAcsClient client = new DefaultAcsClient(profile);
  5. 调用返回结果
    DescribeDBInstanceAttributeResponse response =client.getAcsResponse(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();
        }

返回示例

{"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"}