Support Questions

Find answers, ask questions, and share your expertise
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Error connecting to Hive from Spark

New Contributor

Hello everybody,

I am able to connect to beeline, using !connect, with following jdbc string

jdbc:hive2://<server_name>:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2 no problem.

However I cannot connect using exactly same jdbc string from Spark


val currentSession = SparkSession .builder() .appName("mainHive") .master("local[*]") .getOrCreate();

val df = .format("jdbc") .option("url",<same_url>) .option("user", <user_name>) .option("password", <password>) .option("dbTable","base") .load();


18/08/10 16:16:05 INFO state.ConnectionStateManager: State change: CONNECTED 18/08/10 16:16:05 INFO zookeeper.ZooKeeper: Session: 0x364f5a35f66441d closed 18/08/10 16:16:05 INFO zookeeper.ClientCnxn: EventThread shut down Exception in thread "main" java.sql.SQLException: Could not open client transport for any of the Server URI's in ZooKeeper: Unable to read HiveServer2 uri from ZooKeeper at org.apache.hive.jdbc.HiveConnection.openTransport( at org.apache.hive.jdbc.HiveConnection.<init>( at org.apache.hive.jdbc.HiveDriver.connect(

Any idea would be appreciated


Any reason why you want to establish a jdbc connection to hive? IIRC there were some issues while accessing hive via jdbc through spark.

Spark can directly connect to hive metastore. Just make sure you have hive-site.xml in /etc/spark/conf/* and create a hive context. Then you can directly access the hive tables. Ref :

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.