java 远程连接 eclipse_使用java(eclipse)远程连接hive

hive 版本apache-hive-1.2.1-bin

1.先启动mysql (sevice mysql start),然后启动hive远程服务,输入:./hive --service hiveserver2 即可

然后命令行会显示等待输入,不用管了这里了,进入第二步吧;

2.引入jar包到项目中

jar包包括:  apache-hive-1.2.1-bin 里面的lib下的jar包,还有hadoop-2.7.1--》share--》hadoop--》common下的hadoop-common-2.7.1.jar

3.在项目中写入以下代码即可

Class.forName("org.apache.hive.jdbc.HiveDriver");

Connection connection = DriverManager.getConnection("jdbc:hive2://192.168.18.130:10000/hive", "root","root");

连接就创建好了(10000后的hive是hive在mysql中对应的数据库名)

例:

public static void main(String[] args) {

try {

Class.forName("org.apache.hive.jdbc.HiveDriver");

Connection connection = DriverManager.getConnection("jdbc:hive2://192.168.18.130:10000/hive", "root","root");

System.out.println(connection);

} catch (ClassNotFoundException e) {

e.printStackTrace();

} catch (SQLException e) {

e.printStackTrace();

}

}

输出结果:

log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

[email protected]

连接成功!!

原文:http://www.cnblogs.com/liumingyi/p/5955670.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值