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」
341 0
DataGrip连接Hive执行DDL操作报错:「FAILED: ParseException line 1:5 cannot recognize input near 'show' 'indexes' 'on' in ddl statement」
|
6月前
|
SQL 关系型数据库 MySQL
Mybatis-Plus(连接Hive)
Mybatis-Plus(连接Hive)
99 0
|
8月前
|
Java 关系型数据库 MySQL
Eclipse使用JDBC连接MySQL数据库详细教程
Eclipse使用JDBC连接MySQL数据库详细教程
|
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)
464 0
Window10 pyhive连接hive报错:Could not start SASL: b‘Error in sasl_client_start (-4) SASL(-4)
|
11月前
|
SQL 分布式计算 网络协议
hive连接被拒
connection refused
123 0
|
11月前
|
SQL 数据库 HIVE
Python连接Hive数据库
Python连接Hive数据库
|
SQL Java 数据库连接
本地客户端 dbeaver-连接HIVE库
本地客户端 dbeaver-连接HIVE库 hive库管理套件
本地客户端 dbeaver-连接HIVE库
|
SQL XML Java
Eclipse中Java使用JDBC连接数据库(c3p0)
Eclipse中Java使用JDBC连接数据库(c3p0)
Eclipse中Java使用JDBC连接数据库(c3p0)
|
关系型数据库 MySQL Java
java eclipse 连接mysql数据库并操纵数据库
java eclipse 连接mysql数据库并操纵数据库
87 0
|
SQL Java 关系型数据库
eclipse连接MySQL
eclipse连接MySQL以及JDBC
169 0

推荐镜像

更多