我想知道是否以及如何连接到我使用的HBaseTestTable (org.apache.hadoop.hbase.HBaseTestingUtility;)通过Phoenix。我希望成功连接到Hbase,然后插入Test表并从Test表中检索数据。我已经能够创建一个HbaseTable。但无法通过凤凰城连接到它。也无法使用writeToPhoenix函数。
我正在分享我写的代码:
@BeforeClass
public static void init() throws Exception {
testingUtility = new HBaseTestingUtility();
testingUtility.startMiniCluster();
hbaseConfiguration = testingUtility.getHBaseCluster().getConfiguration();
String zkQuorum = "localhost:" + testingUtility.getZkCluster().getClientPort();
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
java.sql.Connection connection = DriverManager.getConnection("jdbc:phoenix:"+zkQuorum);
connection.setAutoCommit(true);
try {
Statement statement = connection.createStatement();
statement.executeUpdate("CREATE TABLE TEST(" +
"KEY VARCHAR NOT NULL," +
"VALUE1 VARCHAR NOT NULL," +
"VALUE2 VARCHAR NOT NULL," +
"CONSTRAINT PK PRIMARY KEY(KEY)" +
")");
connection.commit();
log.info("HBase table via Phoenix created successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
堆栈追踪:
java.lang.ClassNotFoundException:org.apache.phoenix.jdbc.PhoenixDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
感谢。
答案 0 :(得分:1)
您需要将Phoenix jar文件添加到IntelliJ
中的类路径中