在HBase中,可以使用JavaAPI或HBaseshell来查看表是否存在。
-
使用JavaAPI:
importorg.apache.hadoop.conf.Configuration; importorg.apache.hadoop.hbase.HBaseConfiguration; importorg.apache.hadoop.hbase.HBaseException; importorg.apache.hadoop.hbase.client.Admin; importorg.apache.hadoop.hbase.client.Connection; importorg.apache.hadoop.hbase.client.ConnectionFactory; importorg.apache.hadoop.hbase.client.TableDescriptor; importorg.apache.hadoop.hbase.util.Bytes; public class CheckTableExists{ public static void main (String[]args) throwsHBaseException{ Configuration conf =HBaseConfiguration.create(); Connection connection = null; try{ connection=ConnectionFactory.createConnection(conf); Admin admin =connection.getAdmin(); String tableName = "your_table_name"; boolean tableExists =admin.tableExists(Bytes.toBytes(tableName)); System.out.println( "Tableexists:"+tableExists); } catch(Exceptione){ e.printStackTrace(); } finally{ if(connection!= null){ connection.close(); } } } } -
使用HBaseshell:
$hbaseshell hbase(main):001:0>exists'your_table_name'
以上是检查表是否存在的两种方法,可以根据需要选择一种适合的方式。