Java程序操作Hive
1、hive的lib+jdbc,还要把mysql的连接驱动加载过来
2、编写程序
开启远程服务:
[root@zhiyou ~]# hiveserver2 &
[1] 4127
[root@zhiyou ~]#
package com.zy.test; import java.sql.*; public class HiveTest { public static void main(String[] args) throws Exception { //1.加载驱动 Class.forName("org.apache.hive.jdbc.HiveDriver"); //2.建立连接 String url = "jdbc:hive2://192.168.80.113:10000/default"; String user = "root"; String password = "1234"; Connection conn = DriverManager.getConnection(url, user, password); //3.准备sql语句 String sql = "select Sname from student"; PreparedStatement ps = conn.prepareStatement(sql); //4.执行sql语句 ResultSet rs = ps.executeQuery(); while (rs.next()){ System.out.println(rs.getString(1)); } rs.close(); ps.close(); conn.close(); } }