启动Hive远程服务接口:
bin/hive --service hiveserver
测试代码如下:
package com.hadoop.hive;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class HiveJdbcClient {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://10.2.136.22:10000/default", "", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.executeQuery("drop table " + tableName);
ResultSet res = stmt.executeQuery("create table " + tableName + " (key int, value string)");
// show tables
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
// describe table
sql = "describe " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2));
}
// load data into table
// NOTE: filepath has to be local to the hive server
// NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
String filepath = "/tmp/a.txt";
sql = "load data local inpath '" + filepath + "' into table " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
// select * query
sql = "select * from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
}
// regular hive query
sql = "select count(1) from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1));
}
}
}
分享到:
相关推荐
hive-jdbc
jdbc连接hive数据库的jar包.整理可用合集.
JDBC连接hive,用JD连接hive。
可用于数据库客户端连接、FineReport 等报表工具连接 包含 Jar 包列表: 01、hadoop-common-3.0.0-cdh6.3.1.jar 02、hive-exec-2.1.1-cdh6.3.1.jar 03、hive-jdbc-2.1.1-cdh6.3.1.jar 04、hive-jdbc-2.1.1-cdh6.3.1-...
hive2.1.1 + hadoop2.6.0jdbc驱动,里边并没有包含所有的hive/lib 下的jar包。共有15个,自己在eclipse中测试过完全可用
dbeaver连接hive时需要的驱动包hive-jdbc-uber-2.6.5.0-292.jar
这是用于与HIVE建立JDBC连接的驱动jar包,经过测试,是可以使用的。
hive jdbc驱动 2.5.15 及 2.6.1两个版本,亲测有用!!!
jdbc 连接impala或者jdbc连接hive所需的jar包。
cloudera.com为我们提供的hiveserver2-JDBC驱动包,不需要把10几个jar找齐就能使用了。
压缩包中包含Java通过JDBC连接Hive所需的jar包。包含有,antlr-runtime-3.0.1.jar;commons-logging-1.0.4.jar;hadoop-core-1.2.1.jar;hive-exec-0.10.0.jar;hive-jdbc-0.13.1.jar;hive-metastore-0.9.0.jar;hive-...
使用javaJDBC连接hive数据,实现简单的操作!
一直在网上找不到impalajdbc的pom依赖,项目是maven的,所以整理了所用的pom
hive权限,通过自定义jar对hive的10000端口进行权限管控,直接放入到hive所在的lib环境下,然后对xml文件进行相应的配置
DBeaver链接hive驱动包下载: hive-jdbc-uber-2.6.5.0-292.jar
通过导入jar包,连接hive数据库驱动,DbVisualizer连接Hive数据库所需jar包,包含:hadoop-common-2.2.0.jar,hive-jdbc-2.1.1-standalone.jar,hive-jdbc-2.1.1.jar,满足日常hive查询需求。
DBeaver连接Hive的Jar包,通过Java JDBC连接Hive同样可以使用。 DBeaver连接Hive的Jar包,通过Java JDBC连接Hive同样可以使用。
java使用JDBC连接Hadoop的hive数据库所用jar包,JDBC连接hive具体实现查看https://editor.csdn.net/md/?articleId=103372571
亲测有用,在ambari2.5.2下安装的hadoop版本,后面的版本应该都没问题
hive,jdbc,kettle,驱动包, kettle8.2连接hive驱动包: hive-jdbc-1.1.0-cdh5.14.2.jar