启动远程客户端 # hive --service hiveserver2
获取连接-〉创建运行环境-〉执行HQL-〉处理结果-〉释放资源

工具类

 package demo.utils;

 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class JDBCUtils {
private static String driverString = "org.apache.hive.jdbc.HiveDriver";
private static String urlString = "jdbc:hive2://sd-9c1f-2eac:10000/default";
static {
try {
Class.forName(driverString);
} catch (ClassNotFoundException e) {
throw new ExceptionInInitializerError(e);
}
} public static Connection getConnection() {
try {
return DriverManager.getConnection(urlString);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
} public static void release (Connection conn, Statement st, ResultSet rs){
if (rs!=null){
try{
rs.close();
}catch(SQLException e){
e.printStackTrace();
}finally{
rs=null;
}
}
if (st!=null){
try{
st.close();
}catch(SQLException e){
e.printStackTrace();
}finally{
st=null;
}
}
if (conn!=null){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}finally{
conn=null;
}
}
} }

JDBCUtil.java

测试类

 package demo.hive;

 import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import demo.utils.JDBCUtils; public class HiveJDBCDemo {
public static void main(String[] args) {
Connection conn=null;
Statement st=null;
ResultSet rs=null;
String sql="select * from sampledata";
conn=JDBCUtils.getConnection();
try {
st=conn.createStatement();
rs = st.executeQuery(sql);
while(rs.next()){
String sid = rs.getString(1);
String sname = rs.getString(2);
String gender = rs.getString(3);
System.out.println(sid+" "+sname+" "+gender);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
JDBCUtils.release(conn, st, rs);
} } }

HiveJDBCDemo.java

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/PL62716/workspace/HiveDemo/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/PL62716/workspace/HiveDemo/lib/slf4j-log4j12-1.7.22.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
1 Tom M
2 Mary F
3 Jerry M
4 Rose M
5 Mike F

add hive/lib->all jar and hadoop->share->hadoop->common->hadoop-common.jar to project build path.

Hive进阶_Hive的客户端操作的更多相关文章

  1. Hive进阶_Hive的子查询

    - 集合中如果含null数据,不可使用not in, 可以使用in- hive只支持where和from子句中的子查询- 主查询和自查询可以不是同一张表 select e.ename from emp ...

  2. Hive进阶_Hive数据查询

    简单查询和fetch task 简单查询:   简单查询的 fetch task 功能,从HDFS拉取,不用map reduce. 前两种配置,当前session有效.修改hive-site.xml永 ...

  3. Hive进阶_Hive的表连接

    等值连接 select e.empno, d.deptno from emp e, dept d where e.deptno=d.deptno; 不等值连接 select e.empno, e.en ...

  4. Hive进阶_Hive数据的导入

    使用Load语句执行数据的导入 语法: load data [local] inpath 'filepath' [overwrite] into table tablename [partition ...

  5. Hive进阶(下)

    Hive进阶(下) Hive进阶(下) Hive的表连接 等值连接 查询员工信息:员工号.姓名.月薪.部门名称 1.select e.empno,e.ename,e.sal,d.dname2.from ...

  6. Hive HiveServer2+beeline+jdbc客户端访问操作

    HiveServer 查看/home/hadoop/bigdatasoftware/apache-hive-0.13.1-bin/bin目录文件,其中有hiveserver2 启动hiveserver ...

  7. Hive学习(三)Hive的Java客户端操作

    Hive的Java客户端操作分为JDBC和Thrifit Client,首先启动Hive远程服务: hive --service hiveserver 一.JDBC 在MyEclipse中首先创建连接 ...

  8. Hive进阶(上)

    Hive进阶(上) Hive进阶(上) 执行数据导入 使用Load语句 语法: 1.LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE ...

  9. python 全栈开发,Day124(MongoDB初识,增删改查操作,数据类型,$关键字以及$修改器,"$"的奇妙用法,Array Object 的特殊操作,选取跳过排序,客户端操作)

    一.MongoDB初识 什么是MongoDB MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介 ...

随机推荐

  1. PHP5.3之后的新特性【转】

    http://blog.csdn.net/black_ox/article/details/21163193

  2. Eclipse中导入github上的项目

    Eclipse中导入github上的项目 转载至: http://blog.csdn.net/hil2000/article/details/8566456 1.首先在github.com上申请一个账 ...

  3. CSDN不登陆看博文

    做前端的朋友说,手动改太Low,给了段JS代码: javascript: void((function() {var divElement = document.getElementById('art ...

  4. zabbix告警邮件美化

    为了更好的用户体验,我们需要尽量美化我们的输出内容,尽量做到整齐划一,让人看了会有很舒服的感觉, 这个好像和苹果的产品一样,给人一种美感让人感觉非常享受. 一般我们的zabbix告警邮件就是纯文字,建 ...

  5. C++多态的实现条件

    #include <iostream> class Person{ public: virtual void say(){ std::cout<<"person&qu ...

  6. POJ3694(求割边)

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7943   Accepted: 2893 Descripti ...

  7. Arduino 元件

    http://www.rs-online.com/designspark/electronics/

  8. [poj1986]Distance Queries(LCA)

    解题关键:LCA模板题 复杂度:$O(n\log n)$ #pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...

  9. Mysql定时执行任务实现方法

    http://blog.csdn.net/zlp5201/article/details/38309095

  10. string实现

    #include<iostream> using namespace std;   class String{     friend ostream& operator<&l ...