phoenix客户端API使用

时间:2022-04-21 08:37:14

1.准备条件

phoenix与Hbase已经安装好
phoenix-4.3.0
hbase-0.98

2.客户端使用(服务器上使用客户端)

在客户端创建如下文件test.java:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class test {

    public static void main(String[] args) throws SQLException {
        Statement stmt = null;
        ResultSet rset = null;

        Connection con = DriverManager.getConnection("jdbc:phoenix:[zookeeper]");
        stmt = con.createStatement();

        stmt.executeUpdate("create table test (mykey integer not null primary key, mycolumn varchar)");
        stmt.executeUpdate("upsert into test values (1,'Hello')");
        stmt.executeUpdate("upsert into test values (2,'World!')");
        con.commit();

        PreparedStatement statement = con.prepareStatement("select * from test");
        rset = statement.executeQuery();
        while (rset.next()) {
            System.out.println(rset.getString("mycolumn"));
        }
        statement.close();
        con.close();
    }
}

编译:

$javac test.java

执行:
$ java -cp "../phoenix-[version]-client.jar:." test

3.参考文献

http://phoenix.apache.org/faq.html