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("john.m.doe@gmail.com"));
table.put(put);
table.flushCommits();
table.close();
System.out.println("Table created");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
线程中的异常" main" java.lang.IllegalArgumentException:不是 主机:端口对:PBUFhadoop�}�����*�} at org.apache.hadoop.hbase.util.Addressing.parseHostname(Addressing.java:60) 在org.apache.hadoop.hbase.ServerName。(ServerName.java:96)at org.apache.hadoop.hbase.ServerName.parseVersionedServerName(ServerName.java:278) at org.apache.hadoop.hbase.MasterAddressTracker.bytesToServerName(MasterAddressTracker.java:77) 在 org.apache.hadoop.hbase.MasterAddressTracker.getMasterAddress(MasterAddressTracker.java:61) 在 org.apache.hadoop.hbase.client.HConnectionManager $ HConnectionImplementation.getMaster(HConnectionManager.java:631) 在 org.apache.hadoop.hbase.client.HBaseAdmin。(HBaseAdmin.java:106) 在 com.networkfleet.hbase.practice.HbaseConnectorClass.creatTable(HbaseConnectorClass.java:82)在 com.networkfleet.hbase.practice.HbaseConnectorClass.main(HbaseConnectorClass.java:63)
答案 0 :(得分:1)
很可能是由于HBase服务器和HBase客户端jar之间的版本不匹配
检查您的服务器和客户端版本