我正在尝试使用java api连接apache phoenix,代码如下:
public class SampleHbasePhoenixConnection {
static final String DB_URL = "jdbc:phoenix:hbaseServer:hbasePort:/";
public static void main(String args[]) throws Exception {
Connection conn = null;
Statement st = null;
try {
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
System.out.println("Connecting to database..");
conn = DriverManager.getConnection(DB_URL);
System.out.println("Creating statement...");
st = conn.createStatement();
String sql;
sql = "SELECT top 10 * FROM HBaseTable";
ResultSet rs = st.executeQuery(sql);
rs.close();
st.close();
conn.close();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (st != null)
st.close();
} catch (SQLException se2) {
se2.printStackTrace();
}
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
}
}
下面是我在pom.xml中添加的依赖项
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.0.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>5.0.0-HBase-2.0</version>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix</artifactId>
<version>5.0.0-HBase-2.0</version>
<type>pom</type>
</dependency>
我使用的hbase版本是“1.2.0-cdh5.12.0”。运行代码时,出现以下异常:
Exception in thread "main" com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/CellComparatorImpl
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2254)
at com.google.common.cache.LocalCache.get(LocalCache.java:3985)
at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4788)
at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:241)
at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.createConnection(PhoenixEmbeddedDriver.java:150)
at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:221)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at SampleHbaseConnection.main(SampleHbaseConnection.java:35)
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/CellComparatorImpl
at org.apache.phoenix.hbase.index.util.KeyValueBuilder.get(KeyValueBuilder.java:71)
at org.apache.phoenix.query.ConnectionQueryServicesImpl.<init>(ConnectionQueryServicesImpl.java:398)
at org.apache.phoenix.jdbc.PhoenixDriver$3.call(PhoenixDriver.java:248)
at org.apache.phoenix.jdbc.PhoenixDriver$3.call(PhoenixDriver.java:241)
at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4791)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3584)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2372)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2335)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2250)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.CellComparatorImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 17 more
我很少看到其他帖子,我只使用这些帖子创建了这个连接url。我无法摆脱这个例外。有什么建议吗?
1条答案
按热度按时间s4chpxco1#
我猜您的4.0.0孵化版phoenix core与您的hbase客户端版本不兼容。
然而,您仍然有第二个版本的who看起来是兼容的,但不幸的是,在运行时并不是第一个版本。
只需删除此依赖项:
如果还不够,请尝试将hbase客户端版本升级到2.1。