hive的jdbc使用
①新建maven项目,加载依赖包
在pom.xml中添加
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.1</version>
</dependency>
②启动hive的service,启动集群
(hive1.2.1版本以后需要使用hiveserver2启动)
hive –-service hiveserver2 –-hiveconf hive.server2.thrift.port=11111(开启服务并设置端口号)

③配置core-xite.xml
<property>
<name>hadoop.proxyuser.neworigin.groups</name>
<value>*</value>
<description>Allow the superuser oozie to impersonate any members of the group group1 and group2</description>
</property>
<property>
<name>hadoop.proxyuser.neworigin.hosts</name>
<value>*</value>
<description>The superuser can connect only from host1 and host2 to impersonate a user</description>
</property>
④编写java代码
package com.neworigin.HiveTest1; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement; public class JDBCUtil {
static String DriverName="org.apache.hive.jdbc.HiveDriver";
static String url="jdbc:hive2://s100:11111/myhive";
static String user="neworigin";
static String pass="123";
//创建连接
public static Connection getConn() throws Exception{
Class.forName(DriverName);
Connection conn = DriverManager.getConnection(url,user,pass);
return conn;
}
//创建命令
public static Statement getStmt(Connection conn) throws SQLException{
return conn.createStatement();
}
public void closeFunc(Connection conn,Statement stmt) throws SQLException
{
stmt.close();
conn.close();
}
}
package com.neworigin.HiveTest1; import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement; public class JDBCTest {
public static void main(String[] args) throws Exception {
Connection conn = JDBCUtil.getConn();//创建连接
Statement stmt=JDBCUtil.getStmt(conn);//创建执行对象
String sql="select * from myhive.employee";//执行sql语句
String sql2="create table jdbctest(id int,name string)";
ResultSet set = stmt.executeQuery(sql);//返回执行的结果集
ResultSetMetaData meta = set.getMetaData();//获取字段
while(set.next())
{
for(int i=1;i<=meta.getColumnCount();i++)
{
System.out.print(set.getString(i)+" ");
}
System.out.println();
}
System.out.println("第一条sql语句执行完毕");
boolean b = stmt.execute(sql2);
if(b)
{
System.out.println("成功");
} }
}
hive的jdbc使用的更多相关文章
- Hive的JDBC使用&并把JDBC放置后台运行
使用JDBC访问HIVE: 首先启动hive的JDBC服务. 进入hive的bin目录: 这样启动是启动到前台.如果 要想启动到后台需要用到Linux的相关命令. 我们先把其放到前台看下效果,之后再把 ...
- [Hive_5] Hive 的 JDBC 编程
0. 说明 Hive 的 JDBC 编程 1. hiveserver2 介绍 hiveserver2 是 Hive 的 JDBC 接口,用户可以连接此端口来连接 Hive 服务器 JDBC 驱动类为 ...
- Hive的JDBC
Hive 的JDBC 包含例子 https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-JDBC HiveServ ...
- hive安装 jdbc链接hive
1. 下载hive安装包 2. 进入 conf 中 : cp hive-default.xml.template hive-site.xml, vi hive-site.xml 1)首行添加: ...
- Hive和Jdbc示例
重要:在使用 JDBC 开发 Hive 程序时, 必须首先开启 Hive 的远程服务接口.使用下面命令进行开启:hive -service hiveserver & 1). 测试数据 user ...
- SPARK_sql加载,hive以及jdbc使用
sql加载 格式 或者下面这种直接json加载 或者下面这种spark的text加载 以及rdd的加载 上述记得配置文件加入.mastrt("local")或者spark://m ...
- Hive的JDBC访问
实现hive查询源码: String driverName = "org.apache.hive.jdbc.HiveDriver"; try { Class.forName(dri ...
- Hive:JDBC示例
1)本地目录/home/hadoop/test下的test4.txt文件内容(每行数据之间用tab键隔开)如下所示: [hadoop@master test]$ sudo vim test4.txt ...
- Hive的JDBC连接
首相要安装好hive 1.首先修改配置文件文件为hive 路径下的 conf/hive-sit.xml 将内容增加 <property> <name>hive.server2 ...
随机推荐
- 论文笔记之:Heterogeneous Face Attribute Estimation: A Deep Multi-Task Learning Approach
Heterogeneous Face Attribute Estimation: A Deep Multi-Task Learning Approach 2017.11.28 Introductio ...
- Leetcode_Easy_14
编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". class Solution { public String longestCommonP ...
- 在Idea创建Spring Boot + MyBatis的web项目
创建步骤如下 选择Spring initializr 2. 修改group 与 atifact id,点击next 3. dependencies里面选择Web->Web , SQL -> ...
- C#Listview添加数据,选中最后一行,滚屏
this.listView.Items.Add(lvi); this.listView.EnsureVisible(this.listView.Items.Count - 1); this.listV ...
- Perl关联数组用法集锦
本文和大家重点讨论一下Perl关联数组的概念,创建Perl关联数组,从数组变量复制到Perl关联数组,元素的增删,用Perl关联数组循环等内容,相信通过本文的学习你对Perl关联数组的用法一定会有深刻 ...
- 小程序学习一 .json 文件配置
微信小程序——配置 以下就是小编对小程序配置的资料进行的系统的整理,希望能对开发者有帮助. 我们使用app.json文件来对微信小程序进行全局配置,决定页面文件的路径.窗口表现.设置网络超时时间.设置 ...
- linux 换源
Ubuntu换源 ubuntu 的默认源是美国的,所以下载起来特别慢.更换国内源:用vi和gedit 打开 /etc/apt/sources.list 将其中的us.archive 全部替换为 cn. ...
- Vue运行报错--not defined
按F12键进入调试模式,谷歌总是提示Uncaught ReferenceError: ——is not defined这个错误. 原来是因为虽然是传递的值,但是在函数传参的时候也要加引号,加上引号后就 ...
- 基于 Python 和 Pandas 的数据分析(3) --- 输入/输出 基础
这一节, 我们要讨论 Pandas 的输入与输出, 并且应用在现实的实际例子中. 为了得到大量的数据, 向大家推荐一个网站 Quandl. Quandl 有很多免费和付费的资源. 这个网站最大的优势在 ...
- leecode第二十六题(删除排序数组中的重复项)
class Solution { public: int removeDuplicates(vector<int>& nums) { int len=nums.size(); ) ...