想用java操作hbase,遇到了些问题

问题描述

想用java操作hbase,遇到了些问题

新手
在网上看教程,用java在hbase中创建表,输入代码之后问题很多
package hbase;

import java.io.IOException;

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.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

public class hbasetest1 {

private static final String TABLE_NAME = "test1";
private static final String FAMILY_NAME = "cf1";

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.rootdir","hdfs://master:9000/hbase");
    conf.set("hbase.zookeeper.quorum","master:2181");

    HBaseAdmin hBaseAdmin = new HBaseAdmin(conf);

    HTableDescriptor htableDescriptor = new HTableDescriptor(TABLE_NAME);
    htableDescriptor.addFamily(new HColumnDescriptor(FAMILY_NAME));
    hBaseAdmin.createTable(htableDescriptor);
}

}
直接编译运行的话:
log4j:WARN No appenders could be found for logger (org.apache.hadoop.security.Groups).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.apache.hadoop.hbase.TableExistsException: test1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:106)
at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:95)
at org.apache.hadoop.hbase.util.ForeignExceptionUtil.toIOException(ForeignExceptionUtil.java:45)
at org.apache.hadoop.hbase.client.HBaseAdmin$ProcedureFuture.convertResult(HBaseAdmin.java:4617)
at org.apache.hadoop.hbase.client.HBaseAdmin$ProcedureFuture.waitProcedureResult(HBaseAdmin.java:4575)
at org.apache.hadoop.hbase.client.HBaseAdmin$ProcedureFuture.get(HBaseAdmin.java:4508)
at org.apache.hadoop.hbase.client.HBaseAdmin.createTable(HBaseAdmin.java:674)
at org.apache.hadoop.hbase.client.HBaseAdmin.createTable(HBaseAdmin.java:604)
at hbase.hbasetest1.main(hbasetest1.java:29)
Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hbase.TableExistsException): test1
at org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.prepareCreate(CreateTableProcedure.java:287)
at org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.executeFromState(CreateTableProcedure.java:108)
at org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.executeFromState(CreateTableProcedure.java:58)
at org.apache.hadoop.hbase.procedure2.StateMachineProcedure.execute(StateMachineProcedure.java:119)
at org.apache.hadoop.hbase.procedure2.Procedure.doExecute(Procedure.java:465)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execProcedure(ProcedureExecutor.java:1061)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:856)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:809)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.access$400(ProcedureExecutor.java:75)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor$2.run(ProcedureExecutor.java:495)
ant运行:
Buildfile: /home/celine/workspace/test-hbase/build.xml
clean:
[delete] Deleting directory /home/celine/workspace/test-hbase/dist
[delete] Deleting directory /home/celine/workspace/test-hbase/classes
[echo] 清理完毕
init:
[mkdir] Created dir: /home/celine/workspace/test-hbase/classes
[mkdir] Created dir: /home/celine/workspace/test-hbase/dist
compile:
[javac] Compiling 1 source file to /home/celine/workspace/test-hbase/classes
[javac] Note: /home/celine/workspace/test-hbase/src/hbase/hbasetest1.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
jar:
[jar] Building jar: /home/celine/workspace/test-hbase/dist/jar.jar
ssh:
[scp] Connecting to 192.168.124.128:22
[scp] done.
sshexec:
[sshexec] Connecting to 192.168.124.128:22
[sshexec] cmd : source /etc/profile; hadoop jar ~/jar.jar hbase.hbasetest1
[sshexec] Exception in thread "main"
[sshexec] java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
[sshexec] at hbase.hbasetest1.main(Unknown Source)
[sshexec] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[sshexec] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[sshexec] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[sshexec] at java.lang.reflect.Method.invoke(Method.java:606)
[sshexec] at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
[sshexec] at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
[sshexec] Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
[sshexec] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[sshexec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[sshexec] at java.security.AccessController.doPrivileged(Native Method)
[sshexec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[sshexec] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[sshexec] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[sshexec] ... 7 more

BUILD FAILED
/home/celine/workspace/test-hbase/build.xml:72: Remote command failed with exit status 1
每次都说远程有问题,但是我在build.xml里面配好了相关信息,不知道为什么sshexec会失败
TAT刚刚开始学,好难,好多问题……

解决方案

Java操作hbase CURD
Java对hbase的操作
java操作hbase

解决方案二:

没事了……我犯了个傻……

解决方案三:

不对。。。远程还是连不上,求解啊啊啊啊啊

时间: 2024-10-12 07:27:37

想用java操作hbase,遇到了些问题的相关文章

Java在HBase数据库中创建一个数据表的实例

要通过Java在HBase中创建一个数据表,首先需要导入hbase-client.jar驱动包.可以在项目pom.xml配置文件中添加依赖: <dependency>     <groupId>org.apache.hbase</groupId>     <artifactId>hbase-client<artifactId>     <version>1.1.0.1</version><dependency>

基于C#+Thrift操作HBase实践

在基于HBase数据库的开发中,对应Java语言来说,可以直接使用HBase的原生API来操作HBase表数据,当然你要是不嫌麻烦可以使用Thrift客户端Java API,这里有我曾经使用过的 HBase Thrift客户端Java API实践,可以参考.对于具有其他编程语言背景的开发人员,为了获取HBase带来的好处,那么就可以选择使用HBase Thrift客户端对应编程语言的API,来实现与HBase的交互. 这里,我们使用C#客户端来操作HBase.HBase的Thrift接口的定义,

ldap-关于Java操作Ldap,添加用户/用户组时报错

问题描述 关于Java操作Ldap,添加用户/用户组时报错 public static void addUser() { String parentDN = "CN=Users,DC=jovaunn,DC=com"; String childName = "lj1Group"; String childDN = "CN=" + childName + "," + parentDN; Attribute cn = new Bas

Java操作redis

Java操作redis很简单.创建一个普通的Java工程.然后导入redis依赖的jar包.jar包我已经上传了. 1.入门级的demo 入门级demo代码   package com.bjsxt.test;      import redis.clients.jedis.Jedis;      public class RedisDemo {              public static Jedis getJedis(){           Jedis jedis = null;  

java操作mongoDB实现按两个字段排序的问题

问题描述 java操作mongoDB实现按两个字段排序的问题 java操作mongoDB,想通过先按照某一字段排序,在该字段中有相同值时按照另一字段排序,怎么实现? db.adult.find().sort({age:1label1})是直接操作mongoDB的代码 解决方案 .sort(fields) Order by the given fields. There are several equivalent syntaxes:.sort({field1: -1 field2: 1}) de

HBase伪分布式安装(HDFS)+ZooKeeper安装+HBase数据操作+HBase架构体系

HBase1.2.2伪分布式安装(HDFS)+ZooKeeper-3.4.8安装配置+HBase表和数据操作+HBase的架构体系+单例安装,记录了在Ubuntu下对HBase1.2.2的实践操作,HBase的安装到数据库表的操作.包含内容1.HBase单例安装2.HBase伪分布式安装(基于Hadoop的HDFS)过程,3.HBase的shell编程,对HBase表的创建,删除等的命令,HBase对数据的增删查等操作.4.简单概述了Hbase的架构体系.5.zookeeper的单例安装和常用操

NoSQL之Redis(二)---Java操作Redis存储自定义类型数据

NoSQL之Redis(二)---Java操作Redis存储自定义类型数据            Redis简介            Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案.            Redis从它的许多竞争继承来的三个主要特点: Redis数据库完全在内存中,使用磁盘仅用于持久性. 相比许多键值数据存储,Redis拥有一套较为丰富的数据类型. Redis可以将数据复制到任意数量的从服务器.           

想要学习java

问题描述 我还没有学习java只学了点c++面向对象设计,想要知道应该这样学java先帮我介绍java初步了解一下java,然后告诉我下学习java的网站,还有我想要手机类方向发展,安卓的,学习java后该学习什么,给安卓打好基础,能帮我打造出坚实的基础给个方向,谢谢! 解决方案 解决方案二:推荐21天精通java这本书,多下载些视频,好好学吧解决方案三:多看视频,动手编程解决方案四:张孝祥的视频感觉不错解决方案五:觉得楼主既然了解了C++,有C基础,首先应该看:thinkinjava,也就是j

JAVA操作XML实例分析_java

本文实例讲述了JAVA操作XML的方法.分享给大家供大家参考.具体如下: java代码如下: 复制代码 代码如下: import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.w3c.dom.*; import org.xml.sax.SAXException; import javax.xml.