我是靠谱客的博主 稳重灰狼,最近开发中收集的这篇文章主要介绍hive jdbc权限不够_hive权限控制介绍,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

packagecom.hive.jdbc;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.sql.Statement;

importorg.apache.log4j.Logger;

publicclass HiveJdbcClient {

private static String driverName ="org.apache.hadoop.hive.jdbc.HiveDriver";

private static String url ="jdbc:hive://192.168.153.100:10000/default";

private static String user ="hive";

private static String password = "hive";

private static String sql ="";

private static ResultSet res;

private static final Logger log =Logger.getLogger(HiveJdbcClient.class);

public static void main(String[] args){

try {

Class.forName(driverName);

Connection conn =DriverManager.getConnection(url, user, password);

Statement stmt =conn.createStatement();

// 创建的表名

String tableName ="testHiveJDBC";

/** 第一步:存在就先删除**/

sql = "drop table" + tableName;

stmt.executeQuery(sql);

/** 第二步:不存在就创建**/

sql = "createtable " + tableName + " (key int, value string)

row formatdelimited fields terminated by 't'";

stmt.executeQuery(sql);

// 执行“show tables”操作

sql = "show tables'" + tableName + "'";

System.out.println("Running:" + sql);

res = stmt.executeQuery(sql);

System.out.println("执行“show tables”运行结果:");

if (res.next()) {

System.out.println(res.getString(1));

}

// 执行“describe table”操作

sql = "describe" + tableName;

System.out.println("Running:" + sql);

res =stmt.executeQuery(sql);

System.out.println("执行“describe table”运行结果:");

while (res.next()){

System.out.println(res.getString(1) + "t" +res.getString(2));

}

// 执行“load data intotable”操作

String filepath ="/home/hadoop/ziliao/userinfo.txt";

sql = "load datalocal 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);

System.out.println("执行“select * query”运行结果:");

while (res.next()) {

System.out.println(res.getInt(1) + "t" + res.getString(2));

}

// 执行“regular hive query”操作

sql = "selectcount(1) from " + tableName;

System.out.println("Running:" + sql);

res =stmt.executeQuery(sql);

System.out.println("执行“regular hive query”运行结果:");

while (res.next()) {

System.out.println(res.getString(1));

}

conn.close();

conn = null;

} catch (ClassNotFoundExceptione) {

e.printStackTrace();

log.error(driverName +" not found!", e);

System.exit(1);

} catch (SQLException e) {

e.printStackTrace();

log.error("Connection error!", e);

System.exit(1);

}

}

}

最后

以上就是稳重灰狼为你收集整理的hive jdbc权限不够_hive权限控制介绍的全部内容,希望文章能够帮你解决hive jdbc权限不够_hive权限控制介绍所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部