欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

hive java api 博客分类: hive hive 

程序员文章站 2024-03-15 11:43:47
...
1.启动 hadoop
start-all.sh

2.启动hive
./hive --service hiveserver2

3.新建Java 工程
导入jar包
导入hive\lib目录下的hive-jdbc-1.2.0-standalone.jar
导入hadoop-2.7.1\share\hadoop\common下的hadoop-common-2.7.1.jar

4.编写jdbc代码执行
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.242.101:10000/park","root","root");
Statement statement = conn.createStatement();
//statement.executeUpdate("create table x2xx (id int,name string)");
statement.close();
conn.close();




public class HiveJDBC {

	public static void main(String args[]) throws Exception{
		
		Class.forName("org.apache.hive.jdbc.HiveDriver");
		Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.76.131:10000/park","root","zhangbiao");
		PreparedStatement ps = conn.prepareStatement("select * from ext_student");
		ResultSet rs = ps.executeQuery();
		while(rs.next()){
			System.out.println("id:"+rs.getString(1)+" name:"+rs.getString(2));
		}
		rs.close();
		ps.close();
		conn.close();

	}
}

相关标签: hive