{"id":4509,"date":"2014-11-04T19:20:35","date_gmt":"2014-11-05T00:20:35","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=4509"},"modified":"2014-11-04T19:20:35","modified_gmt":"2014-11-05T00:20:35","slug":"hbase-phoenix-jdbc-example","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2014\/11\/04\/hbase-phoenix-jdbc-example\/","title":{"rendered":"HBase Phoenix JDBC example"},"content":{"rendered":"<p>Phoenix is an apache project that attempts to provide an ANSI SQL standard interface to HBase data.  This is just a quick implementation of it.  Notice it has transactional semantics.<\/p>\n<p>Code below&#8230;<\/p>\n<pre>\r\nimport java.sql.*;\r\nimport java.util.*;\r\n\r\npublic class phoenixTest {\r\n  public static void main(String args[]) throws Exception {\r\n    Connection conn;\r\n    Properties prop = new Properties();\r\n    Class.forName(\"org.apache.phoenix.jdbc.PhoenixDriver\");\r\n    conn =  DriverManager.getConnection(\"jdbc:phoenix:localhost:\/hbase-unsecure\");\r\n    System.out.println(\"got connection\");\r\n    ResultSet rst = conn.createStatement().executeQuery(\"select * from stock_symbol\");\r\n    while (rst.next()) {\r\n      System.out.println(rst.getString(1) + \" \" + rst.getString(2));\r\n    }\r\n    System.out.println(conn.createStatement().executeUpdate(\"delete from stock_symbol\"));\r\n    conn.commit();\r\n    rst = conn.createStatement().executeQuery(\"select * from stock_symbol\");\r\n    while (rst.next()) {\r\n      System.out.println(rst.getString(1) + \" \" + rst.getString(2));\r\n    }\r\n    System.out.println(conn.createStatement().executeUpdate(\"upsert into stock_symbol values('IBM','International Business Machines')\"));\r\n    conn.commit();\r\n  }\r\n}\r\n<\/pre>\n<p>&#8230;with the call example below&#8230;<\/p>\n<pre>\r\n[root@sandbox ~]# env | grep CLASSPATH\r\nCLASSPATH=.:\/root\/phoenix-4.1.0-bin\/hadoop2\/phoenix-4.1.0-client-hadoop2.jar\r\n[root@sandbox ~]# java phoenixTest\r\nlog4j:WARN No appenders could be found for logger (org.apache.hadoop.conf.Configuration.deprecation).\r\nlog4j:WARN Please initialize the log4j system properly.\r\nlog4j:WARN See http:\/\/logging.apache.org\/log4j\/1.2\/faq.html#noconfig for more info.\r\ngot connection\r\nIBM International Business Machines\r\n1\r\n1\r\n[root@sandbox ~]#\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Phoenix is an apache project that attempts to provide an ANSI SQL standard interface to HBase data. This is just a quick implementation of it. Notice it has transactional semantics. Code below&#8230; import java.sql.*; import java.util.*; public class phoenixTest {&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2014\/11\/04\/hbase-phoenix-jdbc-example\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,31],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/4509"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=4509"}],"version-history":[{"count":2,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/4509\/revisions"}],"predecessor-version":[{"id":4512,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/4509\/revisions\/4512"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=4509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=4509"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=4509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}