当前位置: 首页 > news >正文

如何自己做企业网站做外贸登录国外网站

如何自己做企业网站,做外贸登录国外网站,合肥网站建设怎么样,网站建设前期预算Apache HBase 是一个开源的、分布式的、可扩展的大数据存储系统#xff0c;它基于 Google 的 Bigtable 模型。使用 Java 操作 HBase 通常需要借助 HBase 提供的 Java API。以下是一个基本的示例#xff0c;展示了如何在 Java 中连接到 HBase 并执行一些基本的操作#xff0c…Apache HBase 是一个开源的、分布式的、可扩展的大数据存储系统它基于 Google 的 Bigtable 模型。使用 Java 操作 HBase 通常需要借助 HBase 提供的 Java API。以下是一个基本的示例展示了如何在 Java 中连接到 HBase 并执行一些基本的操作如创建表、插入数据、扫描表以及删除数据。 一、前提条件 HBase 安装和配置确保 HBase 已经在你的环境中正确安装和配置。 Hadoop 环境HBase 依赖于 Hadoop因此 Hadoop 也需要正确安装和配置。 HBase Java 客户端库你需要将 HBase 的客户端库添加到你的 Java 项目中。通常这可以通过 Maven 或 Gradle 来完成。 二、Maven 依赖 使用 Maven 来管理项目依赖可以在 pom.xml 文件中添加以下依赖 dependenciesdependencygroupIdorg.apache.hbase/groupIdartifactIdhbase-client/artifactIdversion2.4.9/version !-- 请根据你的 HBase 版本选择合适的版本 --/dependencydependencygroupIdorg.apache.hadoop/groupIdartifactIdhadoop-common/artifactIdversion3.3.1/version !-- 请根据你的 Hadoop 版本选择合适的版本 --/dependency /dependencies三、建立连接 在使用HBase Java API之前首先需要建立与HBase的连接。这通常涉及到配置HBase的连接信息如Zookeeper的地址和端口等。 Configuration configuration HBaseConfiguration.create(); configuration.set(hbase.zookeeper.quorum, your_zookeeper_quorum); // 设置Zookeeper的地址 configuration.set(hbase.zookeeper.property.clientPort, your_zookeeper_port); // 设置Zookeeper的端口 Connection connection ConnectionFactory.createConnection(configuration);四、对表的操作 创建表 创建表需要指定表名和列族。HBase中的表是由列族构成的每个列族下可以包含多个列。 Admin admin connection.getAdmin(); if (!admin.tableExists(TableName.valueOf(your_table_name))) {HTableDescriptor tableDescriptor new HTableDescriptor(TableName.valueOf(your_table_name));tableDescriptor.addFamily(new HColumnDescriptor(your_column_family));admin.createTable(tableDescriptor); }删除表 在删除表之前需要先禁用该表。 if (admin.tableExists(TableName.valueOf(your_table_name))) {admin.disableTable(TableName.valueOf(your_table_name));admin.deleteTable(TableName.valueOf(your_table_name)); }判断表是否存在 boolean exists admin.tableExists(TableName.valueOf(your_table_name));列出所有表 HTableDescriptor[] tables admin.listTables(); for (HTableDescriptor table : tables) {System.out.println(table.getNameAsString()); }五、对数据的操作 添加数据 添加数据需要指定表名、行键、列族、列名以及对应的值。 Table table connection.getTable(TableName.valueOf(your_table_name)); Put put new Put(Bytes.toBytes(your_row_key)); put.addColumn(Bytes.toBytes(your_column_family), Bytes.toBytes(your_column), Bytes.toBytes(your_value)); table.put(put); table.close();获取数据 获取数据可以使用Get类来指定要获取的行键和列。 Table table connection.getTable(TableName.valueOf(your_table_name)); Get get new Get(Bytes.toBytes(your_row_key)); get.addColumn(Bytes.toBytes(your_column_family), Bytes.toBytes(your_column)); Result result table.get(get); byte[] value result.getValue(Bytes.toBytes(your_column_family), Bytes.toBytes(your_column)); String valueStr Bytes.toString(value); table.close();扫描数据 扫描数据可以使用Scan类来指定要扫描的表、列族、列等条件。 Scan scan new Scan(); scan.setCaching(500); // 设置每次扫描的缓存大小 scan.setCacheBlocks(false); // 设置是否缓存数据块 scan.addFamily(Bytes.toBytes(your_column_family)); // 添加要扫描的列族ResultScanner scanner table.getScanner(scan); for (Result result : scanner) {// 处理扫描结果byte[] rowKey result.getRow();String rowKeyStr Bytes.toString(rowKey);// 获取指定列的值byte[] value result.getValue(Bytes.toBytes(your_column_family), Bytes.toBytes(your_column));String valueStr Bytes.toString(value);// 输出结果System.out.println(RowKey: rowKeyStr , Value: valueStr); } scanner.close(); table.close();删除数据 删除数据需要指定表名、行键以及要删除的列可选。 Table table connection.getTable(TableName.valueOf(your_table_name)); Delete delete new Delete(Bytes.toBytes(your_row_key)); delete.addColumn(Bytes.toBytes(your_column_family), Bytes.toBytes(your_column)); // 可选指定要删除的列 table.delete(delete); table.close();六、关闭连接 在完成所有操作后需要关闭与HBase的连接以释放资源。 connection.close();七、示例代码 以下是一个完整的 Java 示例代码展示了如何连接到 HBase 并执行基本的操作 import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.hbase.util.Bytes;import java.io.IOException;public class HBaseExample {public static void main(String[] args) {// 创建 HBase 配置对象Configuration config HBaseConfiguration.create();config.set(hbase.zookeeper.quorum, localhost); // 设置 Zookeeper 地址config.set(hbase.zookeeper.property.clientPort, 2181); // 设置 Zookeeper 端口// 创建连接对象try (Connection connection ConnectionFactory.createConnection(config);Admin admin connection.getAdmin()) {// 创建表createTable(admin, my_table, my_column_family);// 插入数据insertData(connection, my_table, row1, my_column_family, column1, value1);// 扫描表scanTable(connection, my_table);// 删除数据deleteData(connection, my_table, row1, my_column_family, column1);// 删除表可选// deleteTable(admin, my_table);} catch (IOException e) {e.printStackTrace();}}private static void createTable(Admin admin, String tableName, String columnFamily) throws IOException {TableName table TableName.valueOf(tableName);if (!admin.tableExists(table)) {HTableDescriptor tableDescriptor new HTableDescriptor(table);HColumnDescriptor columnDescriptor new HColumnDescriptor(columnFamily);tableDescriptor.addFamily(columnDescriptor);admin.createTable(tableDescriptor);System.out.println(Table created: tableName);} else {System.out.println(Table already exists: tableName);}}private static void insertData(Connection connection, String tableName, String rowKey, String columnFamily, String column, String value) throws IOException {TableName table TableName.valueOf(tableName);try (Table table connection.getTable(table)) {Put put new Put(Bytes.toBytes(rowKey));put.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(column), Bytes.toBytes(value));table.put(put);System.out.println(Data inserted: rowKey , column value);}}private static void scanTable(Connection connection, String tableName) throws IOException {TableName table TableName.valueOf(tableName);try (Table table connection.getTable(table);ResultScanner scanner table.getScanner(new Scan())) {for (Result result : scanner) {System.out.println(Scanned row: Bytes.toString(result.getRow()));result.getNoVersionMap().forEach((family, familyMap) - {familyMap.forEach((qualifier, value) - {System.out.println(Family: Bytes.toString(family) , Qualifier: Bytes.toString(qualifier) , Value: Bytes.toString(value.get()));});});}}}private static void deleteData(Connection connection, String tableName, String rowKey, String columnFamily, String column) throws IOException {TableName table TableName.valueOf(tableName);try (Table table connection.getTable(table)) {Delete delete new Delete(Bytes.toBytes(rowKey));delete.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(column));table.delete(delete);System.out.println(Data deleted: rowKey , column);}}private static void deleteTable(Admin admin, String tableName) throws IOException {TableName table TableName.valueOf(tableName);if (admin.tableExists(table)) {admin.disableTable(table);admin.deleteTable(table);System.out.println(Table deleted: tableName);} else {System.out.println(Table does not exist: tableName);}} }说明 创建配置对象使用 HBaseConfiguration.create() 创建 HBase 配置对象并设置 Zookeeper 的地址和端口。创建连接对象使用 ConnectionFactory.createConnection(config) 创建 HBase 连接对象。创建表通过 Admin 接口的 createTable 方法创建表。插入数据使用 Put 对象将数据插入到指定的表中。扫描表使用 Scan 对象扫描表并获取数据。删除数据使用 Delete 对象删除指定的数据。删除表如果需要删除表可以先禁用表然后删除表此操作在示例中是注释掉的以防止意外删除。 注意事项 确保 HBase 和 Zookeeper 正在运行并且配置正确。根据你的 HBase 和 Hadoop 版本调整依赖版本。在生产环境中务必进行充分的错误处理和资源管理如关闭连接和释放资源。
http://www.w-s-a.com/news/678671/

相关文章:

  • 郑州炫彩网站建设网站集约化建设调研报告
  • 2016年两学一做教育网站优良的定制网站建设制作商
  • 自己做网站需要哪些流程网站建设服务费如何做会计分录
  • 莆田建站培训用手机制作游戏的app软件
  • 中山建网站找哪家wordpress采集图片插件
  • 网站首页做后台链接有什么好用的模拟建站软件
  • 宁波有没有开发网站的公司网站上线除了备案还需要什么
  • 网站备案授权wordpress默认主体设置
  • 厦门微信网站广州推广策划公司
  • 集团公司网站开发asp网站怎么运行
  • 广州短视频网站开发东莞市建设信息网
  • 建设网站如果赚钱电脑可以做服务器部署网站吗
  • 网站建设的编程专门做面包和蛋糕的网站
  • 档案网站建设比较分析南京建站公司
  • 哪个网站可以做店招傻瓜式wordpress
  • 网站开发项目经理职责青岛模版网站建设
  • 企业建站哪个好网站建设所用程序
  • 网站建设seo视频定制图片软件
  • 404错误直接转向到网站首页四川省建筑施工企业人员考试平台
  • 手表电商网站智能展厅
  • 南海网站推广梅州做网站公司
  • 昆明专业网站建设公司成都外贸网站建设费用
  • php mysql网站开发项目公司网站宣传设计
  • 自己做网站服务器的备案方法怎么查网站点击量
  • 信息产业部icp备案中心网站织梦做双语网站
  • 爱站网站长seo综合查询工具局网站信息内容建设 自查报告
  • 我想建一个网站怎么建淄博网站推广那家好
  • 做网站和app需要多久河南自助建站建设代理
  • 大连做企业网站的公司宣传平台有哪些类型
  • 如何用微信做网站免费设计logo网站有哪些