JDBC连接Hive

来源:互联网 发布:提示windows找不到aero 编辑:程序博客网 时间:2024/05/22 03:46

Hive 3种连接模式 :

  1. CLI :命令行界面(Command Line Interface for batch scripting),即在hive的bin目录下通过 ./hive命令启动的shell命令行界面
  2. WebUI  : 通过 ./hive –service hwi 来启动,端口9999
  3. Hiveserver: ./bin/hive --service hiveserver & 命令,开启hive的远程服务,并连接。


在这次使用JDBC连接hive的实验中,之前不熟悉,看完那个上的资料乱齐了一堆服务,然后用JDBC连接,但是连接的时候一直没反应也不报错

我想应该是我的服务起错了,后来就网上查资料一直尝试。

后来启动hiveserver的时候报了10000端口被占用的错误,意思到是自己气的东西太乱,占用了端口,于是kill -9 pid 吧起的RnJar程序全部关掉,重启成功

[root@cluster01 apache-hive-0.13.0-bin]# Starting Hive Thrift Server
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.min.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.reduce.tasks.speculative.execution is deprecated. Instead, use mapreduce.reduce.speculative
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.min.split.size.per.node is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.node
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.min.split.size.per.rack is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.rack
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.max.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.maxsize
17/11/08 01:20:24 INFO Configuration.deprecation: mapred.committer.job.setup.cleanup.needed is deprecated. Instead, use mapreduce.job.committer.setup.cleanup.needed
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/cluster/hadoop-2.2.0/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/cluster/hbase-0.96.2-hadoop2/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
OK


JAVA通过JDBC连接Hive,hive并未设置用户名和密码,设置用户名密码参考连接如下:http://blog.csdn.net/lr131425/article/details/72628001

public class JDBCConnect extends UDF{private static String driverName =            "org.apache.hadoop.hive.jdbc.HiveDriver";public static void main(String[] args) throws SQLException {try {Class.forName(driverName);} catch (ClassNotFoundException e) {e.printStackTrace();}System.out.println("#############");Connection con = DriverManager.getConnection(                "jdbc:hive://192.168.159.101:10000/default", "", "");System.out.println("********************");Statement stmt = con.createStatement();        String tableName = "angers_hive_test";        stmt.execute("drop table if exists " + tableName);        stmt.execute("create table " + tableName +                                     " (key int, value string)");        System.out.println("Create table success!");}}