Hive-beeline、jdbc、regex

服务端启动

配置文件是Hive的配置文件

服务端启动

hiveserver2

客户端启动

  1. 进入后连接
$ beeline
beeline> !connect jdbc:hive2://node2:10000
Connecting to jdbc:hive2://node2:10000
Enter username for jdbc:hive2://node2:10000: root
Enter password for jdbc:hive2://node2:10000:

默认端口号为10000,用户名使用root,无密码

  1. 直接连接
beeline -u jdbc:hive2://node2:10000 -u root

JDBC

pom.xml文件



    4.0.0

    com.avcdata
    boot2hive2
    1.0-SNAPSHOT

    
        
            
                org.apache.maven.plugins
                maven-assembly-plugin
                2.4
                
                    
                        jar-with-dependencies
                    
                    
                        
                            com.avcdata.Main
                        
                    
                
                
                    
                        package
                        
                            single
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    8
                    8
                
            
        
    
    
        
        
            org.apache.hive
            hive-jdbc
            1.2.1
        

        
        
            org.apache.hadoop
            hadoop-common
            2.6.0
        

        
        
            com.alibaba
            fastjson
            1.2.49
        


    
    
        
            central
            Central Repository
            http://repo.maven.apache.org/maven2
            default
            
                false
            
        
    


Java代码

package com.avcdata;


import com.alibaba.fastjson.JSONObject;

import java.sql.*;
import java.util.List;
import java.util.Map;

public class Main {

    public static void main(String[] args) throws SQLException {
        try {
            String driverName = "org.apache.hive.jdbc.HiveDriver";
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Connection conn = DriverManager.getConnection("jdbc:hive2://node2:10000", "root", "");
        Statement stmt = conn.createStatement();
        String sql = "SELECT * FROM psn7";
        ResultSet rs = stmt.executeQuery(sql);


        while (rs.next()) {
            List likes = JSONObject.parseArray(rs.getString(3), String.class);
            Map address = JSONObject.parseObject(rs.getString(4), Map.class);
            System.out.println(rs.getString(1) + "\t" + rs.getString(2));
            System.out.println(likes);
            System.out.println(address);
        }
    }
}

你可能感兴趣的:(Hive-beeline、jdbc、regex)