首先启动HiveServer
hive --service hiveserver 10000 &
创建工程
引入包:
代码(简单的查询):
package com.hive.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class HiveJDBC { public static void main(String[] args) { try { Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver"); // 查询语句 String querySQL = "SELECT * FROM t_rp"; // 链接hive Connection con = DriverManager.getConnection("jdbc:hive://192.168.0.100:10000/default", "hive", "hive"); Statement stmt = con.createStatement(); // 执行查询语句 ResultSet res = stmt.executeQuery(querySQL); while (res.next()) { System.out.println("Result: key:" + res.getString(1) + " –> value:" + res.getString(2)); } stmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }
eclipse 远程操作HIVE,布布扣,bubuko.com
原文:http://blog.csdn.net/jameshadoop/article/details/30364409