Created 05-06-2019 09:24 PM
Hello,
I am new in Sandbox HDP, I am trying to connect to Hive using JDBC, I used the JDBC URL given by Ambari, and here is my code:
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException { try { Class.forName(driverName); } catch (ClassNotFoundException e) { e.printStackTrace(); System.out.println(e.getMessage()); } Connection con = DriverManager.getConnection( "jdbc:hive2://sandbox-hdp.hortonworks.com:2181/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2"); }
However, I got this error:
Exception in thread "main" java.sql.SQLException: Invalid URL: jdbc:hive2://sandbox-hdp.hortonworks.com:2181/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2 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(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at Hive2.main(Hive2.java:21)
I've tried a lot of urls but not working..
please if someone can help to solve this issue, it will be appreciated
Created 05-07-2019 01:33 AM
Your driverName seems to be slightly different.
You are using "org.apache.hadoop.hive.jdbc.HiveDriver" so can you please try using the "org.apache.hive.jdbc.HiveDriver" class name to see if it works.
then see if it works?
There is a simple example available here you might want to quickly test it: https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/HDP_Ambari/Hive/HiveJavaClient
Also can you please let us know how exactly are you running it? Like how you are setting the classpath... may be some incorrect/different version of JARs are there in your classpath.
Created 05-07-2019 01:33 AM
Your driverName seems to be slightly different.
You are using "org.apache.hadoop.hive.jdbc.HiveDriver" so can you please try using the "org.apache.hive.jdbc.HiveDriver" class name to see if it works.
then see if it works?
There is a simple example available here you might want to quickly test it: https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/HDP_Ambari/Hive/HiveJavaClient
Also can you please let us know how exactly are you running it? Like how you are setting the classpath... may be some incorrect/different version of JARs are there in your classpath.
Created 05-07-2019 10:05 AM
thank you for your answer, i have tried to use the driver you mentioned but still get the same error.
i am using hive on windows 10 hdp-virtualbox , i included the jar files in my eclipse project.
maybe i am including the wrong files? could you please send me a download link to download all the resources required for the jdbc connector to run with hive on sandbox? and let me know which libraries to include in the classpath or the eclipse project.
Thank you again