本文转载至:http://blog.csdn.net/wind520/article/details/44084953(有个别自己的修改)
注:这里的hive版本是1.2.0,所以用的hiveserver2,区别于hiveserver1,不要混淆使用
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
修改后
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>
- 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://localhost:10001";
- String username="hive";
- String password="hive";
- 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 test"));
- //( "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="";
- }
- }
- }
运行结果: num should be 1
test.name
wangjian