import java.sql.*;
/**
* Description: HiveJdbcClient的操作
* 修改默认的hiveserver2的启动端口:
* $HIVE_HOME/bin/hiveserver2 --hiveconf hive.server2.thrift.port=14000
* $HIVE_HOME/bin/beeline -u jdbc:hive2://localhost:14000 -n hadoop
* 上面的hadoop是指当前用户
*
* @Author: 留歌36
* @Date: 2019/3/4 19:15
*/
public class HiveJdbcClientApp {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive2://192.168.1.102:14000/default", "hadoop", "");
Statement stmt = con.createStatement();
// show tables
String sql = "select * from auto_hive_dept_nums";
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1)+" "+res.getString(2));
}
}
}
HiveJdbcClient的操作 【Hive】
最新推荐文章于 2024-02-13 18:16:40 发布