eclipse远程连接hive

创建项目,添加jar包,hive的s上,所以也需要hadoop的一些jar

这个图片是从网上找的,我直接使用的以前hadoop的项目
 
创建测试类,写测试代码
//获取jdbc链接
private static Connection getConnection(){
Connection conn=null;
try {
//注册驱动
Class.forName("org.apache.hive.jdbc.HiveDriver");
conn=DriverManager.getConnection("jdbc:hive2://node4:10000/default");
// jdbc:hive://localhost:10000/default
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
conn=getConnection();//获取链接
sbSql.append("select * from ");
if(null!=conn){
try {
statement=conn.createStatement();
String tableName="student_1";
sbSql.append(tableName);
//执行sql
rSet=statement.executeQuery(sbSql.toString());
if(null!=rSet){
while(rSet.next()){
System.out.println(rSet.getString(3));
}
}
 
遇到的问题
1.
在使用eclipse链接hive时,总是报:不能够打开一个连接,time out connection,这个是因为我服务器的防火墙没关闭
 
2.报一下错误,需要配置hadoop-core.xml文件
Caused by: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): Unauthorized connection for super-user: root from IP 192.168.177.124
添加如下配置
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
3:
No suitable driver found for jdbc:hive://node4:10000/default
这个异常是因为连接的uri导致的:
在1.2以上的版本使用
//注册驱动
Class.forName("org.apache.hive.jdbc.HiveDriver");
conn=DriverManager.getConnection("jdbc:hive2://node4:10000/default");
在1.2以下的版本使用
//注册驱动
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
conn=DriverManager.getConnection("jdbc:hive://node4:10000/default");
4:有点需要注意的是这个链接的是hive,并不是mysql,所以在链接的uri里链接的是default
 
5:这个异常是因为,在不安全的模式中启动hive,   hive.metastore.execute.setugi这个属性设置为true将导致metastore执行DFS操作使用据客户的用户和组权限
java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: org.apache.hadoop.security.AccessControlException Permission denied: user=anonymous, access=WRITE, inode="/opt/hive/warehouse":root:supergroup:drwxr-xr-x
所以
    一种 是修改hive-site.xml配置文件
<property>
<name>hive.metastore.execute.setugi</name>
<value>false</value>
<description>
在不安全的模式中,将这个属性设置为true将导致metastore执行DFS操作使用
据客户的用户和组权限。请注意,这个属性必须设置
客户端和服务器端。进一步指出,最好的努力。
如果客户端将其设置为真,服务器将它设置为false,客户端设置将被忽略。
</description>
     是,使用安全模式启动hive 
 
 
6:在创建表的时候,如果有定义分区,要先定义分区,否则就会抛出异常
FAILED: ParseException line 1:164 cannot recognize input near 'partitioned' '(' 'sexual' in serde properties specification
 
原文地址:https://www.cnblogs.com/zhangXingSheng/p/6223444.html