Help Center/
DataArts Lake Formation/
Developer Guide/
Using LakeFormation Java SDK to Develop Programs/
Reference Example
Updated on 2024-02-02 GMT+08:00
Reference Example
After the development and running environments are prepared, you can develop samples as required. For example, the reference code is as follows:
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) { // The getAk() and getSk() methods need to be implemented by yourself. You can obtain the AK/SK from the configuration item or other locations. // Do not hard-code AK and SK in codes. String ak = getAk(); String sk = getSk(); // projectId: project ID String projectId = "{******your project id******}"; // 1. Initialize the SDK. HttpConfig config = HttpConfig.getDefaultHttpConfig(); config.withIgnoreSSLVerification(true); List<String> endpoints = new ArrayList<>(); endpoints.add("lakeformation.lakecat.com"); BasicCredentials basicCredentials = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId); // 2. Create a LakeFormationClient instance. LakeFormationClient client = LakeFormationClient.newBuilder() .withHttpConfig(config) .withCredential(basicCredentials) .withEndpoints(endpoints) .build(); // 3. Create a request and add parameters. ListCatalogsRequest listCatalogsRequest = new ListCatalogsRequest().withInstanceId("{******your instance id******}"); // 4. Query the catalog list. 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()); } } }
Parent topic: Using LakeFormation Java SDK to Develop Programs
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot