eclipse开发hive2程序
条件:安装好eclipse和hive
创建项目引入jar包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | package hivetest; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class HiveTest { public static void main(String[] args) throws Exception { Class.forName( "org.apache.hive.jdbc.HiveDriver" ); Connection conn=DriverManager.getConnection( "jdbc:hive2://localhost:10000/default" , "" , "" ); Statement stmt=conn.createStatement(); String query_sql= "select * from people" ; ResultSet rs=stmt.executeQuery(query_sql); String str= "" ; try { ResultSetMetaData rsmd = rs.getMetaData(); for ( int i = 1 ; i <= rsmd.getColumnCount(); i++) { str+=rsmd.getColumnName(i)+ "," ; } System.out.println(str); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } |
遇到的问题:
SunandLi is not allowed to impersonate anonymous
修改core-site.xml中文件内容,在原文件内容中添加:
<property>
<name>hadoop.proxyuser.SunandLi.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.SunandLi.groups</name>
<value>*</value>
</property>
然后重启一下hadoop,等一下运行,因为hadoop刚启动时出去安全模式,运行会报
Name node is in safe mode.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步