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

Running JDBC and Viewing Results

Running JDBC in CLI Mode

  1. On the right of the IntelliJ IDEA home page, click Maven Projects. On the Maven Projects page, choose Project name > Lifecycle and run the clean and compile scripts.

    Figure 1 Maven Projects page

  2. 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.

  3. 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 2 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.
  4. 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.

  5. 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. On the right of the IntelliJ IDEA home page, click Maven Projects. On the Maven Projects page, choose Project name > Lifecycle and run the clean and compile scripts.

    Figure 2 Maven Projects page

  2. 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.

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

    Create table success!
    _c0
    0
    Delete table success!