I followed the steps mentioned in https://luckymrwang.github.io/2018/03/14/Install-hive-on-Mac-with-Homebrew/ to install Apache Hive in Mac book using Homebrew. It installed the version of 3.1.2_3.
I used the command hive and created some tables.
I went to the beeline command line and issued the command !connect jdbc:hive2://
(I did not specify any connection URL as the documentation said there is no need to specify if the hive is installed in the same system) and entered the password as hive and hive as configured in hive-site.xml. It successfully connected to the hive. I used the command show tables
and verified that I am able to see the tables.
Now I try to connect the same via Java JDBC application.
Dependencies:
compile 'org.apache.hive:hive-jdbc:1.1.0'
compile 'org.apache.hadoop:hadoop-client:3.3.0'
Code:
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection connection = DriverManager.getConnection("jdbc:hive2://", "", "");
Statement statement = connection.createStatement();
String table = "CUSTOMER";
statement.executeQuery("DROP TABLE " + table);
However, I keep getting the error as the connection refused. I am not sure whether the connection string is correct or not. Can you please help in resolving the issue?
This is the exception trace
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.ql.metadata.HiveException
I ran hive in debug mode using the command hive --hiveconf hive.root.logger=DEBUG,console
. I didn't see any exceptions there as well.
You can find the hive-site.xml here. https://github.com/Jagannathan6/hive-site.xml/blob/main/hive-site.xml
echo $HADOOP_CLASSPATH in terminal gives the following.
/usr/local/Cellar/hadoop/3.3.0/libexec:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/hive-jdbc-3.1.2.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/hive-exec-3.1.2.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/hive-metastore-3.1.2.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/hive-service-3.1.2.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/libthrift-0.9.3.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/libfb303-0.9.3.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/jdo-api-3.0.1.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/antlr-runtime-3.4.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/datanucleus-api-jdo-4.2.4.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/datanucleus-core-4.1.17.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/datanucleus-rdbms-4.1.19.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/lib/mysql-connector-java-8.0.25.jar:/usr/local/Cellar/hive/3.1.2_3/libexec/conf
The following jars are added in the classpath as well.