0

I wanted to know if and how can I connect to HBaseTestTable which I made using (org.apache.hadoop.hbase.HBaseTestingUtility;) via Phoenix. I want to have a successful connection to Hbase then insert into the Test table and retrieve data from the Test table. I have been able to create a HbaseTable. But unable to connect to it via Phoenix. Also unable to use writeToPhoenix function.

I am sharing the code which I have written:

@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();
    }

}

Stack Trace :

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)

Thanks.

Blank
  • 81
  • 11

1 Answers1

1

You need to add the Phoenix jar file to your classpath in IntelliJ

kliew
  • 3,073
  • 1
  • 14
  • 25