JAVA采用远程连接Hive

1.启动hive
2.启动hive远程服务端口 ---- bin/hive --service hiveserver 50031 &
3.在eclipse创建一个hadoop项目,导入 hadoop.jar,hive等相关的jar包至项目
3.一个测试代码
HiveTestCase.java
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class HiveTestCase {
             public static void main(String[] args) throws  Exception {        
                 Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");        
                 String createSQL="create table javabloger3 (key int, value string)"; 
                 Connection con = DriverManager.getConnection("jdbc:hive://127.0.0.1:50031/default", "", "");
                 Statement stmt = con.createStatement();
                 stmt.executeQuery(createSQL);
                 System.out.println("ok");
             }
}
原文地址:https://www.cnblogs.com/bobsoft/p/2714479.html