【问题标题】:Connect to Test Hbase table via Phoenix通过 Phoenix 连接到 Test Hbase 表
【发布时间】:2017-03-26 05:06:01
【问题描述】:

我想知道我是否以及如何连接到我使用的 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)

谢谢。

【问题讨论】:

  • 发布堆栈跟踪?
  • 完成。我已经编辑了帖子。

标签: java hadoop hbase apache-zookeeper phoenix


【解决方案1】:

您需要将 Phoenix jar 文件添加到 IntelliJ 中的类路径

【讨论】:

    猜你喜欢
    • 2020-11-04
    • 2013-08-23
    • 2015-08-04
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多