MAPREDUCE服务 MRS-Hive JDBC应用开发快速入门:编译并运行程序
编译并运行程序
- 编译JDBC样例程序:
在IDEA界面左下方单击“Terminal”进入终端,执行命令mvn clean package进行编译。
当输出“BUILD SUC CES S”,表示编译成功,如下图所示。编译成功后将会在样例工程的target下生成含有“-with-dependencies”字段的jar包。
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 03:30 min [INFO] Finished at: 2023-05-17T20:22:44+08:00 [INFO] ------------------------------------------------------------------------
- 在本地创建一个目录作为运行目录,如“D:\jdbc_example”,将生成的包名中含有“-with-dependencies”字段的jar包放进该路径下,并在该目录下创建子目录“src/main/resources”。将样例工程“resources”目录下的所有文件拷贝到该目录下。
- 在Windows CMD环境下执行:
cd /d d:\jdbc_example
java -jar hive-jdbc-example-XXX-with-dependencies.jar
- 样例运行成功后,运行信息如下,表示相关Hive表操作成功执行。
... 2023-05-17 20:25:09,421 INFO HiveConnection - Login timeout is 0 2023-05-17 20:25:09,656 INFO HiveConnection - user login success. 2023-05-17 20:25:09,685 INFO HiveConnection - Will try to open client transport with JDBC Uri: jdbc:hive2://192.168.64.216:21066/;principal=hive/hadoop.hadoop.com@HADOOP.COM;sasl.qop=auth-conf;serviceDiscoveryMode=zooKeeper;auth=KERBEROS;zooKeeperNamespace=hiveserver2;user.principal=developuser;user.keytab=src/main/resources/user.keytab 2023-05-17 20:25:30,294 INFO JDBCExample - Create table success! 2023-05-17 20:26:34,032 INFO JDBCExample - _c0 2023-05-17 20:26:34,266 INFO JDBCExample - 0 2023-05-17 20:26:35,199 INFO JDBCExample - Delete table success! ...