创建Phoenix表
功能简介
Phoenix依赖HBase作为其后备存储,支持标准SQL和JDBC API的强大功能,使得SQL用户可以访问HBase集群。
代码样例
以下代码片段在com.huawei.bigdata.hbase.examples包的“PhoenixSample”类的testCreateTable方法中。
/**
* Create Table
*/
public void testCreateTable() {
LOG.info("Entering testCreateTable.");
String URL = "jdbc:phoenix:" + conf.get("hbase.zookeeper.quorum");
// Create table
String createTableSQL =
"CREATE TABLE IF NOT EXISTS TEST (id integer not null primary key, name varchar, "
+ "account char(6), birth date)";
try (Connection conn = DriverManager.getConnection(url, props);
Statement stat = conn.createStatement()) {
// Execute Create SQL
stat.executeUpdate(createTableSQL);
LOG.info("Create table successfully.");
} catch (Exception e) {
LOG.error("Create table failed.", e);
}
LOG.info("Exiting testCreateTable.");
}
/**
* Drop Table
*/
public void testDrop() {
LOG.info("Entering testDrop.");
String URL = "jdbc:phoenix:" + conf.get("hbase.zookeeper.quorum");
// Delete table
String dropTableSQL = "DROP TABLE TEST";
try (Connection conn = DriverManager.getConnection(url, props);
Statement stat = conn.createStatement()) {
stat.executeUpdate(dropTableSQL);
LOG.info("Drop successfully.");
} catch (Exception e) {
LOG.error("Drop failed.", e);
}
LOG.info("Exiting testDrop.");
}