jdbc hive2无效url异常

epggiuax  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(512)

我有一个hortonwork集群(linux),希望使用jdbc从远程主机将数据加载到hive中。我首先尝试让jdbc连接在集群上本地工作,以便在远程尝试之前知道我已经正确地完成了。
hive已成功安装,我可以通过直线连接,没有任何问题:

  1. /usr/lib/hive/bin/beeline
  2. Beeline version 0.13.0.2.1.4.0-632 by Apache Hive
  3. beeline> !connect jdbc:hive2://localhost:10000
  4. scan complete in 3ms
  5. Connecting to jdbc:hive2://localhost:10000
  6. Enter username for jdbc:hive2://localhost:10000: someuser
  7. Enter password for jdbc:hive2://localhost:10000:******
  8. Connected to: Apache Hive (version 0.13.0.2.1.4.0-632)
  9. Driver: Hive JDBC (version 0.13.0.2.1.4.0-632)
  10. Transaction isolation: TRANSACTION_REPEATABLE_READ

我的java类看起来像:

  1. public class HiveConn {
  2. private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
  3. public static void main(String[] args) throws SQLException {
  4. HiveConn myJob = new HiveConn();
  5. myJob.execute();
  6. }
  7. public void execute() throws SQLException {
  8. //mLogger.info("Start HiveJob");
  9. System.out.println("Start HiveJob");
  10. try {
  11. Class.forName(driverName);
  12. } catch (ClassNotFoundException e) {
  13. // TODO Auto-generated catch block
  14. e.printStackTrace();
  15. System.exit(1);
  16. }
  17. Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000", "", "");
  18. //Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000", "root", "");
  19. //Statement stmt = con.createStatement();
  20. String sql = "SHOW TABLES";
  21. System.out.println("Running: " + sql);
  22. System.out.println("HiveJob executed!");
  23. }
  24. }

例外情况:

  1. Start HiveJob
  2. Exception in thread "main" java.sql.SQLException: Invalid URL: jdbc:hive2://localhost:10000/default
  3. at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:86)
  4. at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
  5. at java.sql.DriverManager.getConnection(DriverManager.java:571)
  6. at java.sql.DriverManager.getConnection(DriverManager.java:215)
  7. at HiveConn.execute(HiveConn.java:29)
  8. at HiveConn.main(HiveConn.java:17)

我是以root身份登录的,因此应该没有权限问题。我尝试了所有可能的url组合,包括完整的主机名,比如

  1. jdbc:hive2://servername.company.com:10000
  2. and also adding "default" and user-name in every possible combo to the URL like:
  3. jdbc:hive2://localhost:10000/default "user"
  4. I have tried to add authentication NOSASL to the hive-site.xml and adding it to the URL like:
  5. jdbc:hive2://servername.company.com:10000;auth=NoSasl

我的ip表配置如下所示:

  1. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  2. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  3. ip.address servername.company.com
  4. ip.address servername.company.com
  5. ip.address servername.company.com
  6. ip.address servername.company.com

我不知道还有什么好尝试的。可能是我错过了一些愚蠢的东西。

mutmk8jj

mutmk8jj1#

哦,找到了。我使用了错误的drivername,正确的应该是:

  1. private static String driverName = "org.apache.hive.jdbc.HiveDriver";

被怀疑是个愚蠢的错误。。。

相关问题