通过phoenix连接到测试hbase表

wwodge7n  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(405)

我想知道是否以及如何连接到我使用(org.apache.hadoop.hbase.hbasetestingutility;)创建的hbasetestable途经Phoenix城。我希望成功地连接到hbase,然后插入测试表并从测试表中检索数据。我已经能够创建一个hbasetable。但无法通过Phoenix城连接。也无法使用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)

谢谢。

sz81bmfz

sz81bmfz1#

您需要将phoenix jar文件添加到intellij中的类路径

相关问题