这篇文章主要讲解了“java调用zookeeper模式报错问题怎么处理”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“java调用zookeeper模式报错问题怎么处理”吧!
1.调用方式 zookeeper方式调用
/**
*@Title TestHive.java
*@description TODO
*@time 2020年12月24日 下午1:27:38
*@version 1.0
**/
package org.thedatamanager.dataCollectionService;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
*/
public class TestHive {
/**
* @Title: main
* @Description:
* @param args
* @return void
* @date 2020年12月24日下午1:27:38
*/
public static void main(String[] args) {
try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
//Connection conn = DriverManager.getConnection("jdbc:hive2://10.60.127.131:10000", "hive", "");
// Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.1.135:10000/default;auth=noSasl", "hive", "hive");
Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.1.134:2181,192.168.1.135:2181,192.168.1.136:2181/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2", "root", "root");
// default 为 hive的数据库名
Statement stmt = conn.createStatement();
String querySQL="show databases";
ResultSet res = stmt.executeQuery(querySQL);
while (res.next()) {
System.out.println(res.getString(1));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
报错class undefined找不到curator connection
2.问题
解决方法:,将低版本的hive-jdbc中curator-client低版本的移除 引入高版本的4.0.1
<!-- hive 调用需要的包 -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>3.1.0</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 找不到class undefined问题找不到 curator connection,将低版本的hive-jdbc中curator-client低版本的移除 引入高版本的4.0.1 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>4.0.1</version>
</dependency>
感谢各位的阅读,以上就是“java调用zookeeper模式报错问题怎么处理”的内容了,经过本文的学习后,相信大家对java调用zookeeper模式报错问题怎么处理这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是天达云,小编将为大家推送更多相关知识点的文章,欢迎关注!