启动远程客户端 # 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. URL过滤

    URL过滤 就是网址过滤.把不安全的.少儿不宜的.政治的东西过滤掉,访问这些网址就会提示受限,不能访问. 一.url过滤简介 针对企业对员工上网行为的控制管理,可以采用URL过滤技术.如企业不允许研发 ...

  2. PSPnet:Pyramid Scene Parsing Network——作者认为现有模型由于没有引入足够的上下文信息及不同感受野下的全局信息而存在分割出现错误的情景,于是,提出了使用global-scence-level的信息的pspnet

    from:https://blog.csdn.net/bea_tree/article/details/56678560 2017年02月23日 19:28:25 阅读数:6094 首先声明,文末彩蛋 ...

  3. swift的arc 是不是有问题?

    class Arctest { let name: String = "Arctest" @lazy var ret:() -> String? = { [weak self ...

  4. P4311 士兵占领[最大流]

    题目地址 有一个$M * N$的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵,一个格子里最多可以放置一个士兵,障碍格里不能放置士兵.我们称这些士兵占领了整个棋盘当满足第i行至少放置了$L_ ...

  5. POJ2553( 有向图缩点)

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 9779   Accepted:  ...

  6. gitea (git服务器), 修改配置,更换IP地址

    使用的gitea项目管理git 服务器 (可以不用备份项目, 通过直接修改gitea配置, 直接使用) 步骤1 可以直接访问项目, 步骤2 ,如果已有项目IP地址固定为192.168.1.x, 新的I ...

  7. Redux API之creatStore

    createStore(reducer, [initialState]) 创建一个 Redux store 来以存放应用中所有的 state.应用中应有且仅有一个 store. 参数 reducer  ...

  8. CF-811A

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. B - Simple Game

    B - Simple Game Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  10. 《Java多线程编程核心技术》读后感(二)

    方法内的变量为线程安全 package Second; public class HasSelfPrivateNum { public void addI(String username) { try ...