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…
import java.sql.*;
import java.util.*;
public class phoenixTest {
public static void main(String args[]) throws Exception {
Connection conn;
Properties prop = new Properties();
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
conn = DriverManager.getConnection("jdbc:phoenix:localhost:/hbase-unsecure");
System.out.println("got connection");
ResultSet rst = conn.createStatement().executeQuery("select * from stock_symbol");
while (rst.next()) {
System.out.println(rst.getString(1) + " " + rst.getString(2));
}
System.out.println(conn.createStatement().executeUpdate("delete from stock_symbol"));
conn.commit();
rst = conn.createStatement().executeQuery("select * from stock_symbol");
while (rst.next()) {
System.out.println(rst.getString(1) + " " + rst.getString(2));
}
System.out.println(conn.createStatement().executeUpdate("upsert into stock_symbol values('IBM','International Business Machines')"));
conn.commit();
}
}
…with the call example below…
[root@sandbox ~]# env | grep CLASSPATH CLASSPATH=.:/root/phoenix-4.1.0-bin/hadoop2/phoenix-4.1.0-client-hadoop2.jar [root@sandbox ~]# java phoenixTest log4j:WARN No appenders could be found for logger (org.apache.hadoop.conf.Configuration.deprecation). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. got connection IBM International Business Machines 1 1 [root@sandbox ~]#
1 comment for “HBase Phoenix JDBC example”