1:运行
命令行模式:
hive --service hiveserver2 --hiveconf hive.server2.thrift.port=10001
服务模式:
hiveserver2 start
[jifeng@feng01 conf]$ hive --service hiveserver2 --hiveconf hive.server2.thrift.port=10001 Starting HiveServer2 15/03/05 16:59:33 WARN conf.HiveConf: DEPRECATED: hive.metastore.ds.retry.* no longer has any effect. Use hive.hmshandler.retry.* instead
2:权限问题
java jdbc连接报错:Exception in thread "main" java.sql.SQLException: Error while compiling statement: FAILED: RuntimeException Cannot make directory: hdfs://feng01:9000/tmp/hive-jifeng/hive_2015-03-05_17-04-43_349_5945847416346775092-3 at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:121) at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:109) at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:231) at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:355) at demo.test.Pretest.main(Pretest.java:28)
FAILED: RuntimeException Cannot make directory: hdfs://feng01:9000/tmp/hive-jifeng/hive_2015-03-05_17-04-43_349_5945847416346775092-3无权限创建目录,修改为管理hadoop的用户和密码
修改后
3:For input string: "5000L"
JDBC连接报:
Exception in thread "main" java.sql.SQLException: For input string: "5000L" at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:121) at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:109) at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:263) at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:355) at demo.test.Pretest.main(Pretest.java:28)修改配置:
把hive-site.xml
这个配置文件里hive.server2.long.polling.timeout这个参数是5000L,改成5000
[jifeng@feng01 conf]$ vi hive-site.xml <name>hive.server2.long.polling.timeout</name> <value>5000</value> <description>Time in milliseconds that HiveServer2 will wait, before responding to asynchronous calls that use long polling</description> </property>4:JDBC 连接HIVE OK
package demo.test; import java.sql.*; public class Pretest { public static void main( String args[] ) throws SQLException , ClassNotFoundException { String jdbcdriver="org.apache.hive.jdbc.HiveDriver"; String jdbcurl="jdbc:hive2://feng01:10001"; String username="jifeng"; String password="jifeng"; Class.forName(jdbcdriver); Connection c = DriverManager.getConnection(jdbcurl,username,password); Statement st = c.createStatement(); // select * from firewall where idauto=16600918"));// print( "num should be 1 " , st.executeQuery("select * from course")); //( "select id,name,vip from users order by id limit 5" ) ); // TODO indexing } static void print( String name , ResultSet res ) throws SQLException { System.out.println( name); ResultSetMetaData meta=res.getMetaData(); //System.out.println( "\t"+res.getRow()+"条记录"); String str=""; for(int i=1;i<=meta.getColumnCount();i++){ str+=meta.getColumnName(i)+" "; //System.out.println( meta.getColumnName(i)+" "); } System.out.println("\t"+str); str=""; while ( res.next() ){ for(int i=1;i<=meta.getColumnCount();i++){ str+= res.getString(i)+" "; } System.out.println("\t"+str); str=""; } } }运行结果:
course.id course.c1 course.c2 course.c3 course.c4 1 英语 中文 法文 日文 2 中文 法文 3 中文 法文 日文 4 中文 法文 拉丁 5 中文 法文 德文