Updated on 2024-08-16 GMT+08:00

Preparing a Hive JDBC Development Environment

To run the JDBC API sample code of Hive, you need to perform the following operations.

The following example develops an application that uses JDBC to connect to Hive in the Windows environment.

Procedure

  1. Obtain the Hive sample project by referring to Obtaining the MRS Application Development Sample Project.
  2. In the root directory of the Hive sample project, run the mvn install command to perform compilation.
  3. In the root directory of the Hive sample project, run the mvn eclipse:eclipse command to create an Eclipse project.
  4. In the application development environment, import the sample project to the Eclipse development environment.

    1. Choose File > Import > General > Existing Projects into Workspace > Next > Browse.

      The Browse Folder dialog box is displayed.

    2. Select the hive-examples folder, as shown in Figure 1. On Windows, the folder path cannot contain any space.
      Figure 1 Importing a sample project to Eclipse

      Click Finish.

      After successful import, the JDBCExample class in com.huawei.bigdata.hive.example is the JDBC API sample code.

  5. Set an Eclipse text file encoding format to prevent garbled characters.

    1. On the Eclipse menu bar, choose Window > Preferences.

      The Preferences window is displayed.

    2. In the navigation tree, choose General > Workspace. In the Text file encoding area, select Other and set the value to UTF-8. Click Apply and then OK. Figure 2 shows the settings.
      Figure 2 Setting the Eclipse encoding format

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

    After you obtain the krb5.conf and user.keytab files of the new development user in 5, change the value of userName in ExampleMain.java to the new username, for example, hiveuser.
            /**
             * Other way to set conf for zk. If use this way,
             * can ignore the way in the 'login' method
             */
            if (isSecurityMode) {
                userName = "hiveuser";
                userKeytabFile = CONF_DIR + "user.keytab";
                krb5File = CONF_DIR + "krb5.conf";
                conf.set(HADOOP_SECURITY_AUTHENTICATION, "kerberos");
                conf.set(HADOOP_SECURITY_AUTHORIZATION, "true");