Support Questions

Find answers, ask questions, and share your expertise

Connect hive with zookeeper in java

avatar
Contributor

String url = "jdbc:hive2://huge-agent02:10000/";

Class.forName(driverName);

conn =(Connection) DriverManager.getConnection(url, "hive", "hive");

when i replace url to zookeeper url (jdbc:hive2://huge-server:2181,huge-agent02:2181,huge-agent01:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2), it can not connected hive,why?

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Ye Jun

Are you passing the driverName as "org.apache.hive.jdbc.HiveDriver" ?

Also when you say with the mentioned url it can not connect .... does it mean that you are getting any error? Or is it getting hung for a long time?

Are the host names resolvable from the host where you are running the code?

Example: (from Client machine)

# telnet huge-server  2181
# telnet huge-agent02  2181
# telnet huge-agent01 2181

.

View solution in original post

10 REPLIES 10

avatar
Master Mentor

@Ye Jun

Are you passing the driverName as "org.apache.hive.jdbc.HiveDriver" ?

Also when you say with the mentioned url it can not connect .... does it mean that you are getting any error? Or is it getting hung for a long time?

Are the host names resolvable from the host where you are running the code?

Example: (from Client machine)

# telnet huge-server  2181
# telnet huge-agent02  2181
# telnet huge-agent01 2181

.

avatar
Contributor

Exception in thread "main" java.lang.NullPointerException at org.apache.thrift.transport.TSocket.open(TSocket.java:170) at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:266) at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37) at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:204) at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:176) at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at com.hugedata.hive.HiveJdbcConnect.getConnection(HiveJdbcConnect.java:19) at com.hugedata.hive.HiveTest.main(HiveTest.java:12)

avatar
Master Mentor

@Ye Jun

I see that some issues were reported with the "hive-jdbc" driver version jar. So can you please clarify which exact version of this jar are you using.

As i am able to run my test successfully at my end (for example i am using "http://repo.hortonworks.com/content/repositories/releases/org/apache/hive/hive-jdbc/1.2.1000.2.5.3.0-37/" )

avatar
Master Mentor

@Ye Jun

I have uploaded a sample with the "pom.xml" for version check in the github repo: https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/HDP_Ambari/Hive/HiveJavaClient

avatar
Master Mentor

@Ye Jun

Good to know that the issue is resolved after changing the driver. It will be great if you can mark this HCC thread "Accepted" so that it will be useful for other users as well.

avatar
Contributor

@Jay SenSharma,this is my java code

public class HiveJdbcConnect {

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

private static String url = "jdbc:hive2://huge-server:2181,huge-agent02:2181,huge-agent01:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2";

private static Connection conn = null;

public static Connection getConnection(){

if (conn == null) {

try {

Class.forName(driverName);

conn =(Connection) DriverManager.getConnection(url, "hive", "hive");

} catch (ClassNotFoundException e){

e.printStackTrace();

return null;

} catch (SQLException e) {

e.printStackTrace();

return null;

}

}

return conn;

}

}

avatar
Master Mentor

@Ye Jun

Try using a different version of "hive-jdbc" driver jar for example i am using "http://repo.hortonworks.com/content/repositories/releases/org/apache/hive/hive-jdbc/1.2.1000.2.5.3.0.../"

avatar
Contributor

@Jay SenSharma,Thanks,i try it again.

avatar
Contributor

@Jay SenSharma, i change hive-jdbc version to 1.2.1000.2.5.0.0-1245 ,and solved this problem, thank you for your help.