Updated on 2025-09-18 GMT+08:00

Initializing the Client

To use the Java SDK to access DataArts Fabric SQL, you need to initialize the DataArts Fabric SQL client. You can initialize the client using either a permanent or temporary AK/SK. The sample code is as follows:

Prerequisites

  • You have obtained the required permissions by referring to Important Notes.
  • You have configured the Java SDK and obtained an AK/SK or security token by referring to Preparations.

Sample Code for Permanent AK/SK Authentication

  • Method definition
DwsRestClient(String endpoint, String accessKey, String secretKey)
  • Parameter descriptions

    Parameter

    Mandatory

    Description

    endpoint

    Yes

    Service address provided by DataArts Fabric SQL

    accessKey

    Yes

    Access key ID

    secretKey

    Yes

    Secret access Key

  • Example code
    // Read parameters from environment variables (recommended).
    String endpoint = "example.com";
    String accessKey = System.getenv("FABRICLSQL_ACCESS_KEY");
    String secretKey = System.getenv("FABRICLSQL_SECRET_KEY");
    // (Optional) Check whether the parameters are empty.
    if (endpoint == null || accessKey == null || secretKey == null) {
        throw new IllegalArgumentException("Missing required environment variables");
    }
    DwsRestClient client = new DwsRestClient(endpoint, accessKey, secretKey);

Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables.

This example stores AK and SK in environment variables. Before running this example, set the environment variables FABRICLSQL_ACCESS_KEY and FABRICLSQL_SECRET_KEY in the local environment.

Sample Code for Temporary AK/SK Authentication

  • Method definition
DwsRestClient(String endpoint, String accessKey, String secretKey, String securityToken)
  • Parameter descriptions

    Parameter

    Mandatory

    Description

    endpoint

    Yes

    Service address provided by DataArts Fabric SQL

    accessKey

    Yes

    Temporary access key ID

    secretKey

    Yes

    Temporary secret access key

    securityToken

    Yes

    Temporary access key token

  • Example code
    // Read parameters from environment variables (recommended).
    String endpoint = "example.com";
    String accessKey = System.getenv("FABRICLSQL_ACCESS_KEY");
    String secretKey = System.getenv("FABRICLSQL_SECRET_KEY")
    String securityToken = System.getenv("FABRICLSQL_SECURITY_TOKEN");
    // (Optional) Check whether the parameters are empty.
    if (endpoint == null || accessKey == null || secretKey == null || securityToken == null) {
        throw new IllegalArgumentException("Missing required environment variables");
    }
    DwsRestClient client = new DwsRestClient(endpoint, accessKey, secretKey, securityToken);