Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 05-25-2016 04:30 PM
Is there a simple way to create a table with java in a new deploy of ambari hortonworks 2.4? Libs that I need?
Created 05-25-2016 04:37 PM
CreateHBaseTable.java
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class CreateHBaseTable
{
public static void main(String[] args) throws IOException
{
HBaseConfiguration hconfig = new HBaseConfiguration(new Configuration());
HTableDescriptor htable = new HTableDescriptor("Test");
htable.addFamily( new HColumnDescriptor("id"));
htable.addFamily( new HColumnDescriptor("Name"));
System.out.println( "Connecting..." );
HBaseAdmin hbase_admin = new HBaseAdmin( hconfig );
System.out.println( "Creating Table..." );
hbase_admin.createTable( htable );
System.out.println("Done!");
}
}export HADOOP_CLASSPATH= $HADOOP_PATH:`hbase classpath`
javac -cp `hbase classpath` CreateHBaseTable.java java -cp `hbase classpath` CreateHBaseTable
Created 05-25-2016 04:33 PM
You can find example in refguide (http://hbase.apache.org/book.html#rowkey.regionsplits) :
createTable(Admin admin, HTableDescriptor table, byte[][] splits)Dependencies include hbase-client jar, hbase-protocol jar
Created 05-25-2016 04:34 PM
Search for ".createTable(" in http://hbase.apache.org/book.html
Example 32. Java API
Created 05-25-2016 04:37 PM
CreateHBaseTable.java
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class CreateHBaseTable
{
public static void main(String[] args) throws IOException
{
HBaseConfiguration hconfig = new HBaseConfiguration(new Configuration());
HTableDescriptor htable = new HTableDescriptor("Test");
htable.addFamily( new HColumnDescriptor("id"));
htable.addFamily( new HColumnDescriptor("Name"));
System.out.println( "Connecting..." );
HBaseAdmin hbase_admin = new HBaseAdmin( hconfig );
System.out.println( "Creating Table..." );
hbase_admin.createTable( htable );
System.out.println("Done!");
}
}export HADOOP_CLASSPATH= $HADOOP_PATH:`hbase classpath`
javac -cp `hbase classpath` CreateHBaseTable.java java -cp `hbase classpath` CreateHBaseTable
Created 06-01-2016 02:53 PM
@Jitendra Yadav Your example works fine, thanks a lot. And tanks for the info too @Ted Yu
Created 06-07-2016 05:45 PM
Import the below APIs and try in the lines of below:
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Table;
private static final TableName TABLENAME = TableName.valueOf(“NewTable”);
Table table= null;
Configuration config= HBaseConfiguration.create();
Connection connection == ConnectionFactory.createConnection(config);
table = connection.getTable(TABLENAME);