我正在用Java编写程序,我需要在hive中连接数据库。我使用mysql作为Metastore。 Hadoop,mysql和hive工作没有问题。我已经创建了我的数据库warehousedb和其中的表人员,我也为hirve控制台插入了数据。问题是我打算通过我的Java程序通过JDBC与这个数据库建立连接。我被寻找互联网,我也放了我指出的所有库。
当我执行这些行时会出现一个例外:
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
Connection co = DriverManager.getConnection("jdbc:hive://localhost:9000/warehousedb", "", "");
java.sql.SQLException: org.apache.thrift.transport.TTransportException
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:191)
at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:127)
at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:126)
at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:121)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at connection.Conection.getHiveConnection(Conection.java:38)
at logic.Exc.main(Exc.java:19)
如果我尝试使用hiveserver2:
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
Connection co = DriverManager.getConnection("jdbc:hive2://localhost:9000/warehousedb", "hive", "hive");
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
at org.apache.hive.jdbc.HiveConnection.createUnderlyingTransport(HiveConnection.java:432)
at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:452)
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:193)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:157)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at connection.Conection.getHiveConnection(Conection.java:38)
at logic.Exc.main(Exc.java:19)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
我该如何进行连接?
答案 0 :(得分:0)
首先确定你想要哪个jar(配置单元)..因为它有不同的版本旧的verison jar是
org.apache.hadoop.hive.jdbc.HiveDriver
最新的jar是org.apache.hive.jdbc.HiveDriver
hiveserver2端口为1000
例如
Class.forName(org.apache.hive.jdbc.HiveDriver);
Connection conn = DriverManager.getConnection(jdbc:hive2://192.168.1.1:10000/default);