hive java_hive java 实例

下载  jdo2-api-2.3-ec hive hdfs 所需jar

常见命令

hive 常见命令

create table test(uid string,name string)row format delimited fields terminated by '/t' 见表语句

desc formatted test; 表的约束

desc test; 表的约束

LOAD DATA local INPATH '/root/test3.log' OVERWRITE INTO TABLE test; 本地文件添加数据到hive

LOAD DATA INPATH '/user/hadoop/test5.log' OVERWRITE INTO TABLE test; hdfs 添加数据到hive

select * from test; 查询数据

select count(1) from test; 做mapreduce操作运算需要 hadoop 权限

hdfs 常见命令

hdfs dfs -copyFromLocal test3.log /user/hadoop/test5.log 拷贝

hdfs dfs -cat /user/hadoop/test5.log 查看文件内容

hdfs dfs -lsr /user/hadoop 遍历目录

hdfs dfs -rmr /user/hadoop/storm/ 删除

hdfs dfs -appendToFile test3.log /user/hadoop/test5.log 添加

pom

org.apache.hive

hive-jdbc

0.11.0

org.apache.hadoop

hadoop-common

2.2.0

/**

* @Type HiveTest.java

* @Desc

* @author hadoop

* @date 2016年12月29日 下午2:20:46

* @version

*/

public class HiveTest {

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

public static void main(String[] args)

throws SQLException {

try {

Class.forName(driverName);

} catch (ClassNotFoundException e) {

e.printStackTrace();

System.exit(1);

}

Connection con = DriverManager.getConnection("jdbc:hive2://172.23.27.120:10000/default", "hive", "hive");

Statement stmt = con.createStatement();

String tableName = "test";

//stmt.execute("drop table if exists " + tableName);

//stmt.execute("create table " + tableName + " (key int, value string) row format delimited fields terminated by ','");

// show tables

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

ResultSet res = stmt.executeQuery(sql);

if (res.next()) {

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

}

System.out.println("==================================");

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));

}

System.out.println("==================================");

sql = "select * from " + tableName;

res = stmt.executeQuery(sql);

while (res.next()) {

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

}

System.out.println("==================================");

sql = "select * from " + tableName +" where key ='1' ";

res = stmt.executeQuery(sql);

while (res.next()) {

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

}

sql = "select count(1) from " + tableName;

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

res = stmt.executeQuery(sql);

while (res.next()) {

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

}

System.out.println("==================================");

}

}

07dc5c128178c278dae56e2a62b6236c.png

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。

谢谢您的赞助,我会做的更好!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值