Updated on 2022-09-14 GMT+08:00

Configuring and Importing the JDBC API Sample Project

Scenario

To run the JDBC API sample code of Presto, you need to perform the following operations. The following example develops an application that uses JDBC to connect to Presto in the Windows environment.

Procedure

  1. Obtain the Presto sample project. For details, see Obtaining Sample Projects from Huawei Mirrors.
  2. In the root directory of the Presto sample project, run the mvn install command to perform compilation.
  3. In the root directory of the Presto sample project, run the mvn idea:idea command to create an IntelliJ IDEA project.
  4. Copy the user.keytab and krb5.conf files obtained in Preparing a Developer Account section to the conf directory of the sample project.
  5. Import the example project to the IntelliJ IDEA development environment.

    1. Open IntelliJ IDEA and choose File > Open.
    1. In the Open File or Project dialog box that is displayed, select the Presto sample project folder and click OK. After the folder is imported, the PrestoJDBCExample class is the JDBC API sample code.

  6. Set the IntelliJ IDEA text file coding format to prevent garbled characters.

    1. On the IntelliJ IDEA menu bar, choose File > Settings.
    2. Choose Editor > File Encodings from the navigation tree of the Settings window. In the "Global Encoding" and "Project Encodings" area, set the value to UTF-8, click Apply, and click OK, as shown in Figure 1
      Figure 1 Setting the IntelliJ IDEA coding format

  7. Modify the sample. You can skip this step for a cluster with Kerberos authentication disabled.

    After obtaining the krb5.conf and user.keytab files of the new development user in Preparing a Developer Account, modify KerberosPrincipal in presto.properties to the principal of the new user, KerberosConfigPath to the path of the krb5.conf file, and KerberosKeytabPath to the path of the keytab file.