首页 文章 精选 留言 我的

精选列表

搜索[mysql索引],共10000篇文章
优秀的个人博客,低调大师

Phoenix + HBase,让你像操作MySQL一样操作HBase

Phoenix关联HBase的操作(三种情况) 情况一:Hbase已经有已存在的表了,可在Phoenix中创建对应的视图,视图只能做查询操作,不能做增删改 hbase中已创建表且有数据,表名:phoenix 在phoenix中创建对应视图 create view "phoenix"( pk varchar primary key, "info"."name" varchar, "info"."age" varchar ); 查询视图数据 情况二:Hbase已存在表,可在Phoenix中创建对应的表,对表的操作可读可写,意味着可以对Hbase的表进行插入查询,删除操作。 hbase中已存在表并且有数据 在phoenix中创建对应的表 create table "t_person"( id VARCHAR PRIMARY KEY, "f"."id" VARCHAR, "f"."name" VARCHAR, "f"."age" VARCHAR ) column_encoded_bytes=0; 在phoenix中查询数据 在phoenix中插入数据 此时查看hbase中对应的t_person表数据 情况三:Hbase没有表;可直接在Phoeinx中创建表,对应的Habse中也会自动建表,在Phoenix中对表操作就是直接对Hbase中的表进行操作。 在phoenix中直接建表,t_test表会在hbase中同步创建 插入数据看phoenix和hbase中的效果 通过Java客户端操作phoenix package com.fwmagic.hbase; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.sql.*; /** * 通过Phoenix操作Hbase */ public class PhoenixQueryHbase { Connection connection = null; PreparedStatement ps = null; ResultSet rs = null; @Before public void init() throws Exception { connection = DriverManager.getConnection("jdbc:phoenix:hd1,hd2,hd3:2181"); } /** * 建表并查询 * * @throws Exception */ @Test public void create() throws Exception { Statement statement = connection.createStatement(); statement.executeUpdate("create table test(id integer primary key ,animal varchar )"); //新增和更新都是一个操作:upsert statement.executeUpdate("upsert into test values (1,'dog')"); statement.executeUpdate("upsert into test values (2,'cat')"); connection.commit(); PreparedStatement preparedStatement = connection.prepareStatement("select * from test"); rs = preparedStatement.executeQuery(); while (rs.next()) { String id = rs.getString("id"); String animal = rs.getString("animal"); String format = String.format("id:%s,animal:%s", id, animal); System.out.println(format); } } /** * 查询已有的表 * * @throws Exception */ @Test public void testQuery() throws Exception { String sql = "select * from tc"; try { ps = connection.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { String id = rs.getString("ID"); String name = rs.getString("NAME"); String age = rs.getString("AGE"); String sex = rs.getString("SEX"); String format = String.format("id:%s,name:%s,age:%s,sex:%s", id, name, age, sex); System.out.println(format); } } catch (SQLException e) { e.printStackTrace(); } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (connection != null) connection.close(); } } /** * 删除数据 * * @throws Exception */ @Test public void delete() throws Exception { try { ps = connection.prepareStatement("delete from test where id=2"); ps.executeUpdate(); connection.commit(); } catch (SQLException e) { e.printStackTrace(); } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (connection != null) connection.close(); } } /** * 删除表 * * @throws Exception */ @Test public void dropTable() throws Exception { try { ps = connection.prepareStatement("drop table test"); ps.execute(); } catch (SQLException e) { e.printStackTrace(); } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (connection != null) connection.close(); } } @After public void close() throws Exception { if (rs != null) rs.close(); if (ps != null) ps.close(); if (connection != null) connection.close(); } } 示例代码下载 https://gitee.com/fang_wei/fwmagic-hbase

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码