public class HbaseConnectorClass {

private HTable table;
private static final Logger log = LoggerFactory.getLogger(HbaseConnectorClass.class);

public static void main(String[] args) throws Exception {

    System.out.println("trying to connect ......");
    Configuration conf = HBaseConfiguration.create();

    conf.set("hbase.zookeeper.quorum", "localhost");
    conf.set("hbase.zookeeper.property.clientPort", "2222");
    conf.set("hbase.master", "localhost:60000");

    try
    {
        System.out.println("Hbase is running!");
        HTable table = new HTable(conf,"personal");
        Put put = new Put(Bytes.toBytes("doe-john-m-12345"));
        put.add(Bytes.toBytes("personal"), Bytes.toBytes("givenName"), Bytes.toBytes("John"));
        put.add(Bytes.toBytes("personal"), Bytes.toBytes("mi"), Bytes.toBytes("M"));
        put.add(Bytes.toBytes("personal"), Bytes.toBytes("surame"), Bytes.toBytes("Doe"));
        put.add(Bytes.toBytes("contactinfo"), Bytes.toBytes("email"), Bytes.toBytes("[email protected]"));
        table.put(put);
        table.flushCommits();
        table.close();

        System.out.println("Table created");
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
}
}

最佳答案

最可能是由于HBase服务器与HBase客户端jar之间的版本不匹配

检查您的服务器和客户端版本

07-26 03:55