Maven hive-jdbc教程
由于项目中需要用到hive-jdbc从数据仓库拉数据下来,所以简单的学一下hive,hive数据仓库建构在hadoop集群之上,数据存在hdfs文件系统中,hive中执行的操作会装换成mapreduce作业进行执行,hive支持类似SQL的语言HQL,hive采用元数据对表进行管理,元数据有三种存放模式:嵌入模式,远程模式,本地模式;hive提供了强大的编程接口,hive jdbc可以让你如使用普通的jdbc一般来操作hive表以及数据。
1.添加依赖
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>1.1.0</version>
<exclusions>
<exclusion>
<artifactId>
pentaho-aggdesigner-algorithm
</artifactId>
<groupId>org.pentaho</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.1.0</version>
</dependency>
2.jdbc连接hive
public class TestHive {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";//jdbc驱动路径
private static String url = "jdbc:hive2://hiveserver.xxx.com:10000/dbName";//hive库地址+库名
private static String user = "username";//用户名
private static String password = "pwd";//密码
private static String sql = "";
private static ResultSet res;
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
conn = getConn();
System.out.println(conn);
stmt = conn.createStatement();
String tableName="tab_name";//hive表名
sql = "select * from " + tableName;
System.out.println("Running:" + sql);
res = stmt.executeQuery(sql);
System.out.println("执行 select * query 运行结果:");
while (res.next()) {
System.out.println(res.getInt(1) + "\t" + res.getString(2));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
} catch (SQLException e) {
e.printStackTrace();
System.exit(1);
} finally {
try {
if (conn != null) {
conn.close();
conn = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
private static Connection getConn() throws ClassNotFoundException,
SQLException {
Class.forName(driverName);
Connection conn = DriverManager.getConnection(url, user, password);
return conn;
}
}
3.查询hive表数据
这个就和普通的jdbc差不太多,也是用sql的方式进行查询,具体的查询语法,可以参考hive官网
4.封装hive工具类
写完了再贴上来
@落雨
ae6623.cn
Maven hive-jdbc教程的更多相关文章
- 使用Spring Boot操作Hive JDBC时,启动时报出错误:NoSuchMethodError: org.eclipse.jetty.servlet.ServletMapping.setDef
使用Spring Boot操作Hive JDBC时,启动时报出错误:NoSuchMethodError: org.eclipse.jetty.servlet.ServletMapping.setDef ...
- Hive jdbc连接出现java.sql.SQLException: enabling autocommit is not supported
1.代码如下 String url = "jdbc:hive2://master135:10000/default"; String user = "root" ...
- Hive学习之六 《Hive进阶— —hive jdbc》 详解
接Hive学习五 http://www.cnblogs.com/invban/p/5331159.html 一.配置环境变量 hive jdbc的开发,在开发环境中,配置Java环境变量 修改/etc ...
- maven + selenium + jenkins 教程收集
maven + selenium + jenkins 教程收集 Complete Guide for Selenium integration with jenkins Maven http://le ...
- Hive 8、Hive2 beeline 和 Hive jdbc
1.Hive2 beeline Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式 启动beeline 打开两个Shell窗口,一个启动Hive2 一个beeline连接hi ...
- Hive JDBC:java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not allowed to impersonate anonymous
今天使用JDBC来操作Hive时,首先启动了hive远程服务模式:hiveserver2 &(表示后台运行),然后到eclipse中运行程序时出现错误: java.sql.SQLExcepti ...
- eclipse怎么导入maven项目 eclipse导入maven项目详细教程
转自:http://www.pc6.com/infoview/Article_114542.html Eclipse怎么导入maven项目一直是困扰着大量程序猿和刚上手小白们的问题,使用eclipse ...
- hive JDBC异常到多租户
hive jdbc执行select count(*) from test报错. return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedT ...
- Hive JDBC——深入浅出学Hive
第一部分:搭建Hive JDBC开发环境 搭建:Steps •新建工程hiveTest •导入Hive依赖的包 •Hive 命令行启动Thrift服务 •hive --service hiveser ...
- java.sql.SQLException: Could not establish connection to 192.168.8.111:10000/default: java.net.ConnectException: Connection refused: connect at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveC
java.sql.SQLException: Could not establish connection to 192.168.8.111:10000/default: java.net.Conne ...
随机推荐
- USBDM RS08/HCS08/HCS12/Coldfire V1,2,3,4/DSC/Kinetis Debugger and Programmer -- Software Install
Installation of USBDM for Windows Under Windows, installation is done with a standard Windows MSI fi ...
- AES Test vectors
Table of content List of test vectors for AES/ECB encryption mode AES ECB 128-bit encryption mode AE ...
- WinForm多线程实现HTTP网络检测工具
一.背景描述与课程介绍 明人不说暗话,跟着阿笨一起玩WinForm.本次分享课程属于<C#高级编程实战技能开发宝典课程系列>中的一部分,阿笨后续会计划将实际项目中的一些比较实用的关于C#高 ...
- 在TQ2440上运行perf,生成Flame Graph
参考 http://www.cnblogs.com/helloworldtoyou/p/5585152.html http://blog.csdn.net/mtofum/article/detail ...
- HelloWorld 之JasperReports初步
在企业应用系统中,经常要输出各种格式的数据报表. 著名的开源项目<JasperReports可以很好的解决这个问题. 使用JasperReports可以在预先设定好格式的报表基础上进行数据的填充 ...
- 抄袭证据之中的一个CMM与CMMI的名称
以下文字来自我即将完毕的文章,谢博士说她没有抄袭,可是文中实在是有太多的漏洞了. 6.2.7 P120页中: "实际上终于所谓的统一方法论就是标准,尽管作标准并非目的.但标准是必须有的.能够 ...
- Java获取当前时间30天之前的时间
//方法一 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String maxDateStr = " ...
- 开启VIM的Python支持
开启VIM的Python支持 2015年01月03日 02:57:58 forlong401 阅读数:16294更多 个人分类: VIPython http://www.tuicool.com/a ...
- 用make编译openCV报错:ts_gtest.cpp:(.text._ZN7testing8internal2RED2Ev+0xf): undefined reference to 'regfreeA'
解决方案: the cause is the google tests is looking for the generic regex.h but cmake used the regex.h fr ...
- 标准输出中stderr和stdout的区别
一.首先介绍一下三者printf,sprintf,fprintf的功能 1,printf就是标准输出,在屏幕上打印出一段字符串来. 2,sprintf就是把格式化的数据写入到某个字符串中.返回值字符串 ...