在MyEclipse10上远程连接虚拟机上的Hive,报错:Could not establish connection to 192.168.1.100:10000/log: java.net.Co
来源:互联网 发布:知乎每周精选要qq密码 编辑:程序博客网 时间:2024/06/06 00:56
我是在window10上开发的,远程连接虚拟机上的hive,结果报错:
Exception in thread "main" java.sql.SQLException:Could not establish connection to 192.168.1.100:10000/log: java.net.ConnectException: Connection refused: connect
解决方法:在虚拟机上的终端上输入#hive - -service hiveserver
注意:当你输入上面命令后,出现Starting Hive Thrift Server等等两三行字,代表启动成功了,然后光标会一直闪烁,这时千万别切换回命令行界面,切记!切记!切记!(重要的事情说三遍,因为hive的thrift远程服务似乎是实时性的,返回命令行界面意味着退出thrift服务);现在运行myeclipse中的代码就不会报错了。当你运行成功后,你就可以切换回命令行界面了
下面贴上我的完整代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* 将nginx日志数据导入到hive表中,统计每个用户进入url的次数(使用JDBC执行以上HQL)
* @author 远
*
*/
public class UvHiveJdbc {
private static Connection conn=null;
public static Connection getHiveConn(){
if(conn==null){
try {
System.out.println("==============================");
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
System.out.println("------------------------------");
conn=DriverManager.getConnection("jdbc:hive://192.168.1.100:10000/log","","");
System.out.println("ok");
} catch (Exception e) {
e.printStackTrace();
}
}
return conn;
}
public static void closeHiveConn() throws SQLException{
if(conn!=null){
conn.close();
}
}
public static void execDDL(String sql)throws SQLException{
Connection conn=getHiveConn();
Statement stmt=conn.createStatement();
stmt.execute(sql);
}
public static ResultSet queryData(String sql)throws SQLException{
Connection conn=getHiveConn();
Statement stmt=conn.createStatement();
ResultSet res=stmt.executeQuery(sql);
return res;
}
public static void main(String[] args) {
try {
System.out.println("start");
String sql="create external table access(ip string,day string,url string,refurl string)" +
" row format delimited fields terminated by ',' location '/uvout/'";
System.out.println(sql);
execDDL(sql);
sql="create external table userip(ip string,username string)" +
" row format delimited fields terminated by ' ' location '/userlog/'";
System.out.println(sql);
execDDL(sql);
sql="select a.day,b.username,a.url,count(a.url) from access a join userip b on a.ip=b.ip group by " +
"b.username,a.url,a.day";
System.out.println(sql);
ResultSet res=queryData(sql);
while(res.next()){
System.out.println(res.getString(1)+" "+res.getString(2)+" "+res.getString(3)+
" "+res.getString(4));
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
//关闭hive连接
closeHiveConn();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
- 在MyEclipse10上远程连接虚拟机上的Hive,报错:Could not establish connection to 192.168.1.100:10000/log: java.net.Co
- 在windows的git上用ssh-add添加私钥id_rsa报错——Could not open a connection to your authentication agent.
- 解决AnyConnect在Win8上anyconnect was not able to establish a connection to the specified secure gateway
- Could not establish connection to hadoop0:10000/default: Connection refused: connect
- Could not establish connection to hadoop0:10000/default: Connection refused: connect
- 解决Linux下JSP连接Orcale的著名错误Java.SQL.Exception The Network Adapter could not establish the connection .
- xshell为什么连接不上ubuntu---could not connect to 'ip' (port 22): Connection failed.
- pexpect.pxssh.ExceptionPxssh: Could not establish connection to host
- WordPress could not establish a secure connection to WordPress.org.
- 解决PostgreSQL远程访问报错could not connect to server:Connection refused (0x0000274D/10061)
- 数据库连接报错之IO异常(The Network Adapter could not establish the connection)
- sql developer连接数据库时出现的The Network Adapter could not establish the connection解决办法
- The Network Adapter could not establish the connection没有连接公司的VPN
- Could not connect to '192.168.1.188' (port 22): Connection failed.远程连接centos失败
- vba 用ADO连接不上sqlserver 错误提示:client unable to establish connection
- the network adapter could not establish the connection的解决方法
- 在Myeclipse里创建oracle连接时,出现:The Network Adapter could not establish the connection 错误
- Could not connect to '192.168.80.145' (port 22): Connection failed的解决办法(远程连不上xshell)
- Hibernate的HQL中in参数设置
- Android Studio常用快捷键
- 生成短信验证码的方法
- 【计算机视觉】<前景检测>非参数背景模型介绍<二>
- 《java多线程编程核心技术》读书笔记3:线程间的通信
- 在MyEclipse10上远程连接虚拟机上的Hive,报错:Could not establish connection to 192.168.1.100:10000/log: java.net.Co
- seekg()与tellg()相关文件操作
- c语言之内存管理
- nyoj47 过河问题
- 程序员发展规划
- hibernate自动建表设定字段类型为数据库中为timestamp类型
- Web之Servlet技术
- 关于5509A的有源晶振输出频率的范围
- 《深度探索C++对象模型》- 编译器合成默认构造函数