Created 05-08-2017 10:55 AM
JDBC driver class listed in my Hive configuration is com.mysql.jdbc.Driver.But all the documentation saying that we have to use org.apache.hive.jdbc.HiveDriver.I tried with both of the JDBC Driver class but failed to create a database inside Hive remotely from java.
Created 05-08-2017 12:07 PM
"NoSuchFieldError" Indicates that you might be using older version of JAR in your client classpath. Because the "" field was added as part of fix:
Added in HiveConnection
- https://issues.apache.org/jira/browse/HIVE-10037
- https://github.com/apache/hive/commit/3ee63c1402e9efda6afa5a8d52785299a08b9a57
("HIVE_CLI_SERVICE_PROTOCOL_V8" was added in the "jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java")
.
- Also from the following JIRA the "TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8" " was introduced in the "TProtocolVersion.java" class from JIRA
- https://issues.apache.org/jira/browse/HIVE-12442
-
So please double check your client classpath to find out if older version of jar is being loaded there?
.
Created 05-08-2017 11:19 AM
Are you sure that your remove client has no N/W issue? I mean are you able to connect to the zk hosts like following:
Example if your connection URL is as following
private static String url = "jdbc:hive2://erie3.example.com:2181,erie1.example.com:2181,erie4.example.com:2181,erie2.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2";
- Then try to do a telnet from the client machine to findout if it is able to connect to the mentioned hosts and ports?
# telnet erie1.example.com 2181 # telnet erie2.example.com 2181 # telnet erie3.example.com 2181 # telnet erie4.example.com 2181
.
- Also please refer to the simple HiveClient demo that i placed at my Github repo to see if it works and may you can compare it with your client.
.
For quick testing i wrote the following code to validate if DB creation is happening fine or not?
package client; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class HiveClientDemo { private static String commonDriverName = "org.apache.hive.jdbc.HiveDriver"; private static String url = "jdbc:hive2://erie3.example.com:2181,erie1.example.com:2181,erie4.example.com:2181,erie2.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2"; private static String userName = "hive"; private static String userPass = "hive"; public static void main(String[] args) throws Exception { Class.forName(commonDriverName); Connection con = DriverManager.getConnection(url, userName, userPass); System.out.println("\n\t Got Connection: " + con); System.out.println("*** List the existing Databases...."); Statement stmt = con.createStatement(); String sql = "show databases"; System.out.println("Executing Query: " + sql); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { System.out.println(rs.getString(1)); } sql = "create database Test12345DB"; System.out.println("Executing Query: " + sql); stmt.execute(sql); System.out.println("*** After Creating a new Database...."); sql = "show databases"; System.out.println("Executing Query: " + sql); rs = stmt.executeQuery(sql); while (rs.next()) { System.out.println(rs.getString(1)); } } }
-
I got the following output that shows the newly created Database is showing up properly.
Got Connection: org.apache.hive.jdbc.HiveConnection@65e3690 *** List the existing Databases.... Executing Query: show databases abcd default movielens myretail test test1 test3 testdb testdb_a testdb_c Executing Query: create database Test12345DB *** After Creating a new Database.... Executing Query: show databases abcd default movielens myretail test test1 test12345db test3 testdb testdb_a
.
Please compare the above code with yours and let us know if you see any difference.
- Still if it fails to connect Or fails to create a database then please share the complete stack trace of the error/exception that you receive at the client side.
.
Created 05-08-2017 11:50 AM
Thank you for the quick reply.Itried telnet..its working fine.But now I am getting the error "
Apache Hive client throw NoSuchFieldError: HIVE_CLI_SERVICE_PROTOCOL_V8".
Created 05-08-2017 12:07 PM
"NoSuchFieldError" Indicates that you might be using older version of JAR in your client classpath. Because the "" field was added as part of fix:
Added in HiveConnection
- https://issues.apache.org/jira/browse/HIVE-10037
- https://github.com/apache/hive/commit/3ee63c1402e9efda6afa5a8d52785299a08b9a57
("HIVE_CLI_SERVICE_PROTOCOL_V8" was added in the "jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java")
.
- Also from the following JIRA the "TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8" " was introduced in the "TProtocolVersion.java" class from JIRA
- https://issues.apache.org/jira/browse/HIVE-12442
-
So please double check your client classpath to find out if older version of jar is being loaded there?
.
Created 05-08-2017 12:46 PM
My hive version is 1.2.1...I tried with all the jar files of version related to 1.2.1 which is available,but I am sorry to say that I am getting the same error.
Created 05-09-2017 03:27 AM
@Jay SenSharma...Got it...Thanks a lot...I used jar files of version 1.1 and removed all the older versions of jar..