這篇文章主要介紹HBase JAVA API怎么用,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
pom.xml
<dependencies> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>1.3.5</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-server</artifactId> <version>1.3.5</version> </dependency> </dependencies>
靜態代碼塊
private static Connection connection = null; private static Admin admin = null;; static { try { Configuration configuration = HBaseConfiguration.create(); configuration.set("hbase.zookeeper.quorum", "aliyun:2181"); connection = ConnectionFactory.createConnection(configuration); admin = connection.getAdmin(); } catch (IOException e) { e.printStackTrace(); } }
//創建表 public static void createTable(String tableName, String[] cols) throws IOException { TableName table = TableName.valueOf(tableName); if (admin.tableExists(table)) { System.out.println("表已存在!"); } else { HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName); for (String col : cols) { HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(col); hTableDescriptor.addFamily(hColumnDescriptor); } try { admin.createTable(hTableDescriptor); } catch (IOException e) { e.printStackTrace(); } } }
以上是“HBase JAVA API怎么用”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。