Downloading and Installing the JDBC Driver Package
Scenario
To connect to DLI, JDBC is utilized. You can obtain the JDBC installation package from Maven or download the JDBC driver file from the DLI management console.
This section describes how to connect to DLI and submit a SQL job using JDBC.
Obtaining the Server Connection Address
The address for connecting to DLI is in the format of jdbc:dli://<endPoint>/<projectId>. So, you need to obtain the endpoint and project ID.
Obtain the DLI endpoint from Regions and Endpoints. Specifically, log in to the public cloud, hover over your username in the upper right corner, and choose My Credentials from the shortcut menu. You can obtain the project ID on the displayed API Credentials tab page.
Downloading and Installing the JDBC Driver
![](https://support.huaweicloud.com/intl/en-us/devg-dli/public_sys-resources/note_3.0-en-us.png)
Once JDBC 2.X has undergone function reconstruction, query results can only be accessed from DLI job buckets. To utilize this feature, certain conditions must be met:
- On the DLI management console, choose Global Configuration > Project to configure the job bucket.
- Starting May 2024, new users can directly use DLI's function to write query results into buckets without needing to whitelist it.
For users who started using DLI before May 2024, to use this function, they must submit a service ticket to whitelist it.
- Method 1: Adding the JDBC driver using the Maven central repository
The Maven central repository is part of the Apache Maven project that provides Java libraries and frameworks.
When the JDBC retrieval method is not specified, the default approach is to add the JDBC driver using the Maven central repository.
Use Maven to add the Maven configuration item on which huaweicloud-dli-jdbc depends. (This is the default operation and does not need to be configured separately.)1 2 3 4 5
<dependency> <groupId>com.huawei.dli</groupId> <artifactId>huaweicloud-dli-jdbc</artifactId> <version>x.x.x</version> </dependency>
- Method 2: Obtaining the JDBC driver using Maven to configure the Huawei image source
When using Maven to manage project dependencies, you can modify the settings.xml file to configure the Huawei image source to obtain the JDBC driver.
<mirror> <id>huaweicloud</id> <mirrorOf>*</mirrorOf> <url>https://mirrors.huaweicloud.com/repository/maven/</url> </mirror>
- Method 3: Downloading the JDBC driver file from the DLI management console
- Log in to the DLI management console.
- Click SDK Download in the Common Links area on the right of the Overview page.
- On the DLI SDK DOWNLOAD page, select a driver and download it.
Click huaweicloud-dli-jdbc-x.x.x to download a JDBC driver package.
The JDBC driver package is named huaweicloud-dli-jdbc-<version>.zip. It can be used in all versions of all platforms (such as Linux and Windows) and depends on JDK 1.7 or later.
- The downloaded JDBC driver package contains .bat (Windows) or .sh (Linux/Mac) scripts, which are used to automatically install the JDBC driver to the local Maven repository.
You can choose a script based on your OS to install the JDBC driver.
- Windows: Double-click the .bat file or run the file in the CLI.
- Linux/Mac: Run the .sh script.
Authentication
You need to be authenticated when using JDBC to create DLI driver connections.
- (Recommended) Generating an AK/SK
- Log in to the DLI management console.
- Hover over the username in the upper right corner and select My Credentials from the shortcut list.
- The Projects area is displayed on the API Credentials tab page by default. Choose Access Keys in the navigation pane on the left.
- Click Create Access Key. In the dialog box that appears, set Login Password and SMS Verification Code.
- Click OK to download the certificate.
- Once the certificate is downloaded, you can obtain the AK and SK information in the credentials file.
Hard coding AKs and SKs or storing them in code in plaintext poses significant security risks. You are advised to store them in encrypted form in configuration files or environment variables and decrypt them when needed to ensure security.
- Obtaining a token
When using token-based authentication, you need to obtain the user token and configure the token information in the JDBC connection parameters. You can obtain the token as follows:
- Send POST https://<IAM_Endpoint>/v3/auth/tokens. To obtain the IAM endpoint and region name in the message body, see Regions and Endpoints.
Here is an example request:
Replace the content in italic in the sample code with the actual values. For details, see Identity and Access Management API Reference.
{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", "password": "password", "domain": { "name": "domainname" } } } }, "scope": { "project": { "id": "0aa253a31a2f4cfda30eaa073fee6477" //Assume that project_id is 0aa253a31a2f4cfda30eaa073fee6477. } } } }
- After the request is processed, the value of X-Subject-Token in the response header is the token value.
- Send POST https://<IAM_Endpoint>/v3/auth/tokens. To obtain the IAM endpoint and region name in the message body, see Regions and Endpoints.
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.
For any further questions, feel free to contact us through the chatbot.
Chatbot