Help Center/ MapReduce Service/ Developer Guide (Normal_3.x)/ HBase Development Guide (Security Mode)/ Developing an Application/ Reading/Writing Data/ Creating a Phoenix Table
Updated on 2023-08-31 GMT+08:00
Creating a Phoenix Table
Function
Phoenix can be installed on HBase to enable it to support SQL and JDBC APIs. This way, SQL users can access the HBase cluster.
Example Code
The following code snippet belongs to the testCreateTable method in the PhoenixSample class of the com.huawei.bigdata.hbase.examplespackage.
/**
* 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.");
} Parent topic: Reading/Writing Data
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot