hive连接eclipse

简介: 如何在eclipse中写hive hadoop.proxyuser.qiqi.hosts 主节点地址 hadoop.

1、在Hadoop/etc/core-site.xml中新增

<property>
        <name>hadoop.proxyuser.qiqi.hosts</name>
        <value>主节点地址</value>
</property>
<property>
        <name>hadoop.proxyuser.qiqi.groups</name>
        <value>*</value>
</property>
修改后重启Hadoop
测试:./beeline -u 'jdbc:hive2://localhost:10000/userdb' -n doutao

2、到hive/conf/hive-site.xml文件下,修改文件

<configuration>
    <property> 
      <name>hive.server2.thrift.port</name> 
      <value>10000</value> 
    </property>
    <property>
       <name>hive.server2.thrift.bind.host</name>
       <value>192.168.33.128</value>
    </property>
 </configuration>

3、启动hive服务

hive --service hiveserver2

4、打开eclipse,新建hive项目,导入hive/lib下的jar包

5、代码封装测试

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Hive {
    
    
    Connection con=null;
    Statement statement=null;
    ResultSet res=null;
    
    public boolean openConnection() throws SQLException{
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
            con=DriverManager.getConnection("jdbc:hive2://192.168.147.140:10000/default", "qiqi", "123456");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
        
    }
    
    //select 
    public ResultSet selevtAll(String sql) throws SQLException{
        statement=con.createStatement();
        res=statement.executeQuery(sql);
        return res;
    }
    
    
    //insert update delete
    public boolean updatAll(String sql) throws SQLException{
        statement=con.createStatement();
        boolean re=statement.execute(sql);
        return re;
    }
    
    //close
    public void closeAll(){
        try {
            res.close();
            statement.close();
            con.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }    
    }    
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test {
    
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        
        Hive hive = new Hive();
        
        //String dropSql="drop table kissli";
        //String createSql="CREATE TABLE gool(name String,age int)";
        //String createSql="CREATE TABLE kiss(key string,xm string,nl int)STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ('hbase.columns.mapping' = ':key,hu:xm,huxie:nl') TBLPROPERTIES ('hbase.table.name' = 'kissli1')";
        //String insertSql="insert into gool values('wangzhang',89)";
        String querySql="select * from gool";
        //String sql="drop table fengzi";
        boolean sta=hive.openConnection();
        //System.out.print(hive.updatAll(insertSql));
        
        
        //statement.execute(createSql);
        //statement.execute(insertSql);
        
        ResultSet rs=hive.selevtAll(querySql);
        while(rs.next()){
        System.out.println(rs.getString(1));
        System.out.println(rs.getInt(2));     
        }
        
        hive.closeAll();
}

}
目录
相关文章
|
SQL HIVE
DataGrip连接Hive执行DDL操作报错:「FAILED: ParseException line 1:5 cannot recognize input near 'show' 'indexes' 'on' in ddl statement」
DataGrip连接Hive执行DDL操作报错:「FAILED: ParseException line 1:5 cannot recognize input near 'show' 'indexes' 'on' in ddl statement」
557 0
DataGrip连接Hive执行DDL操作报错:「FAILED: ParseException line 1:5 cannot recognize input near 'show' 'indexes' 'on' in ddl statement」
|
2月前
|
SQL 关系型数据库 MySQL
实时计算 Flink版产品使用问题之如何使用Flink SQL连接带有Kerberos认证的Hive
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
4月前
|
SQL DataWorks 网络安全
DataWorks操作报错合集之DataWorks连接Hive数据库时出现连接超时的问题如何解决
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
|
4月前
|
关系型数据库 MySQL Java
eclipse篇2:如何连接mysql数据库
eclipse篇2:如何连接mysql数据库
|
11月前
|
SQL 关系型数据库 MySQL
Mybatis-Plus(连接Hive)
Mybatis-Plus(连接Hive)
204 0
|
SQL HIVE Python
Window10 pyhive连接hive报错:Could not start SASL: b‘Error in sasl_client_start (-4) SASL(-4)
Window10 pyhive连接hive报错:Could not start SASL: b‘Error in sasl_client_start (-4) SASL(-4)
597 0
Window10 pyhive连接hive报错:Could not start SASL: b‘Error in sasl_client_start (-4) SASL(-4)
|
12月前
|
SQL 存储 大数据
大数据Hive Join连接查询
大数据Hive Join连接查询
76 0
|
Java 关系型数据库 MySQL
Eclipse使用JDBC连接MySQL数据库详细教程
Eclipse使用JDBC连接MySQL数据库详细教程
|
SQL 数据库 HIVE
Python连接Hive数据库
Python连接Hive数据库
|
SQL 分布式计算 网络协议
hive连接被拒
connection refused
202 0

推荐镜像

更多