eclipse 远程操作HIVE

时间:2014-06-15 17:09:46   收藏:0   阅读:375

首先启动HiveServer

hive --service hiveserver 10000 &  

 

创建工程

 

引入包:

bubuko.com,布布扣

代码(简单的查询):

package com.hive.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveJDBC {

	public static void main(String[] args) {
        try {
            Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
            // 查询语句
            String querySQL = "SELECT * FROM t_rp";
            // 链接hive
            Connection con = DriverManager.getConnection("jdbc:hive://192.168.0.100:10000/default", "hive", "hive");
            Statement stmt = con.createStatement();
            // 执行查询语句
            ResultSet res = stmt.executeQuery(querySQL);
            while (res.next()) {
                System.out.println("Result: key:" + res.getString(1) + "  –>  value:" + res.getString(2));
            }
            stmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}

eclipse 远程操作HIVE,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!