问题
I have a Hortonwork cluster (Linux) and want to use JDBC for loading data into Hive from a remote host. I am trying to get the JDBC connection to work locally on the cluster first so that I know I have done it correct before trying remotely.
Hive has been succesfully installed and I can connect through beeline without any problems:
/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
My java class looks like:
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!");
}
}
The exception:
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)
I am logged in as root so should be no permission issues. I have tried every possible Url combo including full hostname like
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
My ip table config looks like:
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
I don't know what to try more. It's probably something silly I am missing.
回答1:
Oops found it. I was using the wrong Drivername and the correct one should be:
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
As suspected a silly mistake...
来源:https://stackoverflow.com/questions/26231049/jdbc-hive2-invalid-url-exception