我正在用java做一个程序,我需要连接hive中的一个数据库。我使用mysql作为metastore。hadoop、mysql和hive工作正常。我已经创建了我的数据库warehousedb和其中的表person,还为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
如何连接?
1条答案
按热度按时间sc4hvdpw1#
首先确定你想要哪个jar(Hive)。。因为它有不同的版本旧的verisonjar是
最新的jar是
org.apache.hive.jdbc.HiveDriver
hiveserver2端口无效1000
例如