Phoenix to a secure HBase cluster

This is just a simple example of using a custom JDBC class to connect to an HBase cluster that is secured by kerberos.

import java.sql.*;
import java.util.*;

public class phoenixTest {
  public static void main(String args[]) throws Exception {
    Connection conn;
    Properties prop = new Properties();
    prop.setProperty("zookeeper.znode.parent","hbase-secure");
    Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
    System.out.println("getting connection");
    conn =  DriverManager.getConnection("jdbc:phoenix:zookeeperhost:2181:[email protected]:/etc/security/keytabs/hbase.headless.keytab");
    System.out.println("got connection");
    try {
      conn.createStatement().execute("create table dim_member(member_key integer primary key,first_name varchar(40), last_name varchar(40))");
    }
    catch (SQLException e) {
      e.printStackTrace();
      Thread.sleep(5000);
    }
    ResultSet rst = conn.createStatement().executeQuery("select * from dim_member");
    while (rst.next()) {
      System.out.println(rst.getString(1) + " " + rst.getString(2));
    }
    System.out.println(conn.createStatement().executeUpdate("delete from dim_member"));
    conn.rollback();
    rst = conn.createStatement().executeQuery("select * from dim_member");
    while (rst.next()) {
      System.out.println(rst.getString(1) + " " + rst.getString(2));
    }
    System.out.println(conn.createStatement().executeUpdate("upsert into dim_member values(1,'Steve','Howard')"));
    conn.commit();
  }
}

1 comment for “Phoenix to a secure HBase cluster

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.