hadoop实现后台修改
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.util.Bytes; public class HBaseUpdateExample { public static void main(String[] args) { // 创建HBase配置对象 Configuration config = HBaseConfiguration.create(); // 配置HBase的Zookeeper地址 config.set("hbase.zookeeper.quorum", "localhost"); config.set("hbase.zookeeper.property.clientPort", "2181"); Connection connection = null; Table table = null; try { // 建立HBase连接 connection = ConnectionFactory.createConnection(config); table = connection.getTable(TableName.valueOf("my_table")); // 创建Put对象 // 参数:rowKey, 列族:列限定符, 值 Put put = new Put(Bytes.toBytes("row1")); put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qualifier"), Bytes.toBytes("new_value")); // 执行Put操作 table.put(put); System.out.println("Data updated successfully!"); } catch (Exception e) { e.printStackTrace(); } finally { // 关闭资源 try { if (table != null) table.close(); if (connection != null) connection.close(); } catch (Exception e) { e.printStackTrace(); } } } }
标签:周四,12,2024.9,hadoop,org,apache,import,hbase,table From: https://www.cnblogs.com/Sunyiran/p/18413944