转载自:http://bbs.hadoopor.com/thread-4724-1-1.html
HTable table = new HTable(configuration,tabName);
这样是可能正常创建table对象
HTablePool pool = new HTablePool(configuration, 1000);
HTable table = (HTable) pool.getTable("tmp_tb");
错误:
2/12/12 16:33:32 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 3260@xuping-c2b2bf6c
Exception in thread "main" java.lang.ClassCastException: org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apache.hadoop.hbase.client.HTable
at com.util.HbaseTest.main(HbaseTest.java:30)
| 问题解决了, 由于我的代码是在网上找的 HTablePool pool = new HTablePool(configuration, 1000); HTable table = (HTable) pool.getTable("tmp_tb"); 其中pool.getTable返回的不是HTable而是HTableInterface 类,直接使用后者提供的put方法即可插入数据(网上的代码返回类型不一致估计是版本的原因) |
讨论了在使用HBase的HTablePool时遇到的ClassCastException问题,并提供了解决方案,即通过pool.getTable方法获取的对象为HTableInterface类型,直接使用此类型提供的put方法即可插入数据。
1506

被折叠的 条评论
为什么被折叠?



