首页 > 代码库 > 通过JDBC驱动连接Hive操作实例 笔记

通过JDBC驱动连接Hive操作实例 笔记

package com.yuxipacific;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
 
public class Hive {
 
    public static void main(String[] args) throws Exception {
         
        Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
         
        //String dropSQL="drop table javabloger";
        //String createSQL="create table javabloger (key int, value string)";
        //String insterSQL="LOAD DATA LOCAL INPATH ‘/work/hive/examples/files/kv1.txt‘ OVERWRITE INTO TABLE javabloger";
        //String querySQL="SELECT a.* FROM javabloger a";
        String querySQL="SELECT * FROM pokes";
         
        Connection con = DriverManager.getConnection("jdbc:hive://192.168.11.124:10000/default""""");
        Statement stmt = con.createStatement();
//        stmt.executeQuery(dropSQL);
//        stmt.executeQuery(createSQL);
//        stmt.executeQuery(insterSQL);
        ResultSet res = stmt.executeQuery(querySQL);
         
        while (res.next()) {
            System.out.println("Result: key:"+res.getString(1) +"  –>  value:" +res.getString(2));
        }
    }
}

通过JDBC驱动连接Hive操作实例 笔记