①新建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使用的更多相关文章

  1. Hive的JDBC使用&并把JDBC放置后台运行

    使用JDBC访问HIVE: 首先启动hive的JDBC服务. 进入hive的bin目录: 这样启动是启动到前台.如果 要想启动到后台需要用到Linux的相关命令. 我们先把其放到前台看下效果,之后再把 ...

  2. [Hive_5] Hive 的 JDBC 编程

    0. 说明 Hive 的 JDBC 编程 1. hiveserver2 介绍 hiveserver2 是 Hive 的 JDBC 接口,用户可以连接此端口来连接 Hive 服务器 JDBC 驱动类为 ...

  3. Hive的JDBC

    Hive 的JDBC 包含例子 https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-JDBC HiveServ ...

  4. hive安装 jdbc链接hive

    1. 下载hive安装包 2. 进入 conf 中  :  cp hive-default.xml.template hive-site.xml,  vi hive-site.xml 1)首行添加: ...

  5. Hive和Jdbc示例

    重要:在使用 JDBC 开发 Hive 程序时, 必须首先开启 Hive 的远程服务接口.使用下面命令进行开启:hive -service hiveserver & 1). 测试数据 user ...

  6. SPARK_sql加载,hive以及jdbc使用

    sql加载 格式  或者下面这种直接json加载 或者下面这种spark的text加载 以及rdd的加载 上述记得配置文件加入.mastrt("local")或者spark://m ...

  7. Hive的JDBC访问

    实现hive查询源码: String driverName = "org.apache.hive.jdbc.HiveDriver"; try { Class.forName(dri ...

  8. Hive:JDBC示例

    1)本地目录/home/hadoop/test下的test4.txt文件内容(每行数据之间用tab键隔开)如下所示: [hadoop@master test]$ sudo vim test4.txt ...

  9. Hive的JDBC连接

    首相要安装好hive 1.首先修改配置文件文件为hive 路径下的  conf/hive-sit.xml 将内容增加 <property> <name>hive.server2 ...

随机推荐

  1. P3244 [HNOI2015]落忆枫音

    思路 给出了一个DAG,要求以1为根的外向树的个数 如果没有加边的条件,就非常好做 每个点都只保留一条入边,最后得到的一定就是一个符合条件的树了(因为给了一个DAG啊) 所以答案是\(\prod_{i ...

  2. 论文笔记:Semantic Segmentation using Adversarial Networks

    Semantic Segmentation using Adversarial Networks 2018-04-27 09:36:48 Abstract: 对于产生式图像建模来说,对抗训练已经取得了 ...

  3. BZOJ 4399 魔法少女LJJ(线段树合并)

    题意 https://www.lydsy.com/JudgeOnline/problem.php?id=4399 思路 码农题,需要一定代码功底.方法很暴力,先将权值离散,表示在线段树里储存的位置,每 ...

  4. 【C#】C# in deep 笔记

    1. delegate and events http://csharpindepth.com/Articles/Chapter2/Events.aspx 2. 显式类型 和 隐式类型 3. 静态类型 ...

  5. 小程序之根据参数更改title

    是这样的,今天呢在写中英文切换功能,哇  从psd图里面去复制英文在去对应,真的是太难受了 okok 切回正题   当用户选择英文的时候   我的title也要是英文怎么办呢 wx.setNaviga ...

  6. colgroup和col的区别

    转载自:http://blog.csdn.net/carefree31441/article/details/3291397 colgroup和col一般出现在表格当中定义表格单独列的任意属性col能 ...

  7. 【log4net】配置文件解释

    ASP.NET MVC 1.web.config: <configSections> <section name="log4net" type="log ...

  8. Mybatis拦截器(一)

    拦截器需要实现 interceptor接口 public interface Interceptor { //3 对目标对象拦截进行处理的内容 Object intercept(Invocation ...

  9. Java SE HashMap的底层实现

    1.hash散列算法 由于hashmap在存储过程中是数组加链表的存储过程,所以定义数组长度为16(建议是2的n次幂的长度),之后进行每个数组的地址都指向一个链表进行存储 hash表算法可对数组长度l ...

  10. java 二维数组的行列长度

    在 java 中,其实只有一维数组,而二维数组是在一维数组中嵌套实现的.比如 int[][] a = {{},{},{},{}} 要取行数和某一行的列数可以 : int rowLen = a.leng ...