
# 参考样例
在准备好开发和运行环境后，用户可根据需求开发样例。
例如使用LakeFormation Java SDK开发程序的参考代码如下：
（如下代码介绍了初始化SDK、创建LakeFormationClient实例、创建请求、添加参数、查询Catalogs列表的相关代码。）
```
package com.huawei.cloud.dalf.lakecat.examples;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ServerResponseException;
import com.huaweicloud.sdk.core.http.HttpConfig;
import com.huaweicloud.sdk.lakeformation.v1.LakeFormationClient;
import com.huaweicloud.sdk.lakeformation.v1.model.ListCatalogsRequest;
import com.huaweicloud.sdk.lakeformation.v1.model.ListCatalogsResponse;
import java.util.ArrayList;
import java.util.List;
public class LakeFormationExample {
    public static void main(String[] args) {
        // getAk(),getSk()方法需自行实现，可以从配置项或其他位置获取AK/SK
        // 请勿在代码中硬编码AK/SK
        String ak = getAk();
        String sk = getSk();
        // projectId: 项目ID
        String projectId = "{******your project id******}";
        // 1.初始化SDK
        HttpConfig config = HttpConfig.getDefaultHttpConfig();
        config.withIgnoreSSLVerification(true);
        List<String> endpoints = new ArrayList<>();
        endpoints.add("<实例ID>.lakeformation.lakecat.com");
        BasicCredentials basicCredentials = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId);
        // 2.创建LakeFormationClient实例
        LakeFormationClient client = LakeFormationClient.newBuilder()
            .withHttpConfig(config)
            .withCredential(basicCredentials)
            .withEndpoints(endpoints)
            .build();
        // 3.创建请求，添加参数
        ListCatalogsRequest listCatalogsRequest =
            new ListCatalogsRequest().withInstanceId("{******your instance id******}");
        // 4.查询Catalogs列表
        try {
            ListCatalogsResponse response = client.listCatalogs(listCatalogsRequest);
            System.out.println(response.getHttpStatusCode());
            System.out.println(response);
        } catch (ClientRequestException | ServerResponseException e) {
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getMessage());
        }
    }
}
```
