这篇文章主要介绍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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。