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

Running JDBC and Viewing Results

Running JDBC in CLI Mode

  1. In the lower left corner of the IDEA page, click Terminal to access the terminal. Run the mvn clean package command to compile the package.

    If BUILD SUCCESS is displayed, the compilation is successful, as shown in the following figure. A JAR file containing the -with-dependencies field is generated in the target directory of the sample project.

  2. Create a directory on Windows or Linux as the running directory, for example, D:\jdbc_example (Windows) or /opt/jdbc_example (Linux). Place the JAR file whose name contains -with-dependencies in the target directory generated in 1 to this directory. Create the src/main/resources subdirectory in the directory. Copy all files in the resources directory of the jdbc-examples project to the resources directory.
  3. In Windows, run the following command:

    cd /d d:\jdbc_example

    java -jar hive-jdbc-example-1.0-SNAPSHOT-jar-with-dependencies.jar

    In Linux, run the following command:

    chmod +x /opt/jdbc_example -R

    cd /opt/jdbc_example

    java -jar hive-jdbc-example-1.0-SNAPSHOT-jar-with-dependencies.jar

    The preceding JAR file names are for reference only. The actual names may vary.

  4. In the CLI, view the HQL query results in the example codes.

    The following information is displayed if the sample project is successful in Windows:
    Create table success!
    _c0
    0
    Delete table success!
    The following information is displayed if the sample project is successful in Linux:
    Create table success!
    _c0
    0
    Delete table success!

Running JDBC in IntelliJ IDEA Mode

  1. Right-click the JDBCExample class in the IntelliJ IDEA jdbc-examples project, and choose Run JDBCExample.main() from the shortcut menu. As shown in the following figure.

  2. In the IntelliJ IDEA output window, view the HQL query results in the example codes.

    Create table success!
    _c0
    0
    Delete table success!