//创建数据库
create datebase hive;//创建表create table t_emp(id int,name string,age int,dept_name string,like array<string>,tedian map<string,string>)row format delimited fields terminated by ','collection items terminated by '_'map keys terminated by ':';ap: 1,zhangsan,32,xxx,sports_books_travel,sex:man_color:red
导入本地文件
load data local inpath '/root/emp.txt' into table t_emp;导出表数据到hdfs
export table t_emp to '/home/xx_t_emp.txt';启动hive服务
启动hive服务之前修改hive-site.xml中的thrift.bind.*为主机名。 ./hive --service hiveserver2java连接hive代码
public static void main(String[] args) throws Exception{ Class.forName("org.apache.hive.jdbc.HiveDriver"); Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.56.101:10000/default","root",""); try { Statement stat = conn.createStatement(); ResultSet result = stat.executeQuery("select count(*) from t_emp"); if(result.next()){ System.out.println(result.getInt(1)); } } catch (Exception e) { e.printStackTrace(); // TODO: handle exception }finally { conn.close(); } }