我试图用简单的java代码截断hbase表:
HBaseAdmin hbaseAdmin = new HBaseAdmin(new HadoopConfig());
但是我得到了“java.lang.reflect.invocationtargetexception”。我看到hbaseadmin构造函数被弃用了。它与hadoop2.2.0配合得很好
lvmkulzt1#
找到下面的代码片段,在java代码中截断hbase表,
Configuration config = HBaseConfiguration.create(); // Add custom config parameters here Connection connection = ConnectionFactory.createConnection(config); Admin admin = connection.getAdmin() admin.truncateTable(TableName.valueOf("bigtable"); admin.close();
希望这有帮助!。
uyto3xhc2#
如果成功,解决方案如下:
Admin admin = null; Configuration config = HBaseConfiguration.create(); // Add custom config parameters here Connection connection = ConnectionFactory.createConnection(config); try { admin = connection.getAdmin(); for (String tableName : tableNames) { System.out.print("Truncate table " + tableName); try { if (HBaseHelper.isTableExists(tableName)) { if (admin.isTableDisabled(TableName.valueOf(tableName))) { System.out.print("Table " + tableName + " was disabled. Enabling it..."); admin.enableTable(TableName.valueOf(tableName ); } HBaseHelper.truncateTable(tableName); } } catch (IOException e) { System.out.print("Failed to truncate table " + tableName + "\nError Msg: " + e.getMessage()); } } } catch (Exception e){ System.out.print("Could not connect to HBase Admin. Error Msg: " + e.getMessage()); }
2条答案
按热度按时间lvmkulzt1#
找到下面的代码片段,在java代码中截断hbase表,
希望这有帮助!。
uyto3xhc2#
如果成功,解决方案如下: