Import the Java. IO. IOException;
Import org, apache hadoop. Conf. Configuration;
Import org, apache hadoop. Hbase. HBaseConfiguration;
Import org, apache hadoop. Hbase. TableName;
Import org, apache hadoop. Hbase. Client. Admin;
Import org, apache hadoop. Hbase. Client. ColumnFamilyDescriptor;
Import org, apache hadoop. Hbase. Client. ColumnFamilyDescriptorBuilder;
Import org, apache hadoop. Hbase. Client. The Connection;
Import org, apache hadoop. Hbase. Client. The ConnectionFactory;
Import org, apache hadoop. Hbase. Client. TableDescriptor;
Import org, apache hadoop. Hbase. Client. TableDescriptorBuilder;
Public class TableAdmin {
Public static Configuration conf;
Public static Connection Connection;
//to get hbase system connection
Public void getconnect () throws IOException {
//get a configuration object
The conf=HBaseConfiguration. The create ();
//because of using the cluster, need to know they are configured on the host and port number
The conf. Set (" hbase. Zookeeper. Quorum ", "datanode2 datanode1:2020:2020, datanode3:2020");
Try {
//to get connection object
The connection=ConnectionFactory. The createConnection (conf);
} the catch (IOException e) {
e.printStackTrace();
}
}
//create a table
Public void createtable () throws IOException {
//create tablename object
TableName TableName=TableName. The valueOf (" the teacher ");
//get the admin object
The Admin Admin=connection. GetAdmin ();
//System. Out. Println (admin);
//check list if there is a
If (admin. TableExists (tableName)) {
//disable table
Admin. DisableTable (tableName);
//delete table
Admin. DeleteTable (tableName);
//hint
System. The out. Println (tableName. ToString () + "repeat and deleted");
}
TableDescriptorBuilder tdescBuild=TableDescriptorBuilder. NewBuilder (tableName);
//create a column family
ColumnFamilyDescriptor baseDataDes=ColumnFamilyDescriptorBuilder. Of (" bastData ");
TdescBuild. SetColumnFamily (baseDataDes);
//create a column family
ColumnFamilyDescriptor professionDataDes=ColumnFamilyDescriptorBuilder. Of (" professionData ");
TdescBuild. SetColumnFamily (professionDataDes);
//build table
TableDescriptor tdesc=tdescBuild. The build ();
Admin. CreateTable (tdesc);
System. The out. Println (" table create success ");
Admin. The close ();
}
}
Package com. Datangedu. Cn. Hbase_test;
Import the Java. IO. IOException;
Public class HbaseTable {
Public static void main (String args []) throws IOException {
TableAdmin TableAdmin=new TableAdmin ();
//get connection
TableAdmin. GetClass ();
//create a table
TableAdmin. Createtable ();
}
}
This error can change
The Exception in the thread "main" Java. Lang. NullPointerException
At com. Datangedu. Cn. Hbase_test. TableAdmin. Createtable (TableAdmin. Java: 40)
At com. Datangedu. Cn. Hbase_test. HbaseTable. Main (HbaseTable. Java: 13)
CodePudding user response:
Bosses help, urgent