我正在尝试使用具有以下代码的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。我无法摆脱这个例外。有什么建议吗?
答案 0 :(得分:0)
我的猜测是,您正在使用4.0.0的Phoenix Core版本与您的Hbase客户端版本不兼容。
但是,您仍然有第二版的《谁》看起来很兼容,但不幸的是在运行时没有被采纳。
只需删除此依赖项即可:
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.0.0-incubating</version>
</dependency>
如果这还不够,请尝试将Hbase Client版本升级到2.1。