2014-10-07 64 views
4

我有一個Hortonwork羣集(Linux)並且想要使用JDBC從遠程主機將數據加載到Hive中。 我想讓JDBC連接在羣集上首先在本地工作,這樣我就知道我在遠程嘗試之前做了正確的操作。Jdbc Hive2無效的Url異常

蜂巢已成功安裝,我可以通過直線連接,沒有任何問題:

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

我的Java類的樣子:

public class HiveConn { 
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver"; 
public static void main(String[] args) throws SQLException { 
HiveConn myJob = new HiveConn(); 
myJob.execute(); 
} 
public void execute() throws SQLException { 
//mLogger.info("Start HiveJob"); 
System.out.println("Start HiveJob"); 
try { 
Class.forName(driverName); 
} catch (ClassNotFoundException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
System.exit(1); 
} 
Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000", "", ""); 
//Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000", "root", ""); 
//Statement stmt = con.createStatement(); 
String sql = "SHOW TABLES"; 
System.out.println("Running: " + sql); 
System.out.println("HiveJob executed!"); 
} 
} 

例外:

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

我我以root身份登錄,因此應該沒有權限問題。 我曾嘗試一切可能的URL組合包括全名狀

jdbc:hive2://servername.company.com:10000 

and also adding "default" and user-name in every possible combo to the URL like: 

jdbc:hive2://localhost:10000/default "user" 

I have tried to add authentication NOSASL to the hive-site.xml and adding it to the URL like: 

jdbc:hive2://servername.company.com:10000;auth=NoSasl 

我的IP地址表的配置是這樣的:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 
::1   localhost localhost.localdomain localhost6 localhost6.localdomain6 
ip.address servername.company.com 
ip.address servername.company.com 
ip.address servername.company.com 
ip.address servername.company.com 

我不知道該怎麼嘗試更多。這可能是我錯過的一些愚蠢的東西。

回答

3

哎呀發現它。 我用錯了驅動程序名和正確的應該是:

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

由於涉嫌愚蠢的錯誤...