使用jdbc连接Phoenix报错

1. 问题截图:

在这里插入图片描述

方便大家搜索,我加一段代码进行搜索错误,也方便我自己查看

Caused by: java.sql.SQLException: ERROR 726 (43M10):  Inconsistent namespace mapping properties. Cannot initiate connection as SYSTEM:CATALOG is found but client does not have phoenix.schema.isNamespaceMappingEnabled enabled
	at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:494)
	at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:150)
	at org.apache.phoenix.query.ConnectionQueryServicesImpl.ensureTableCreated(ConnectionQueryServicesImpl.java:1113)
	at org.apache.phoenix.query.ConnectionQueryServicesImpl.createTable(ConnectionQueryServicesImpl.java:1501)
	at org.apache.phoenix.schema.MetaDataClient.createTableInternal(MetaDataClient.java:2721)
	at org.apache.phoenix.schema.MetaDataClient.createTable(MetaDataClient.java:1114)
	at org.apache.phoenix.compile.CreateTableCompiler$1.execute(CreateTableCompiler.java:192)
	at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:408)
	at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:391)
	at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
	at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:390)
	at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:378)
	at org.apache.phoenix.jdbc.PhoenixStatement.executeUpdate(PhoenixStatement.java:1806)
	at org.apache.phoenix.query.ConnectionQueryServicesImpl$12.call(ConnectionQueryServicesImpl.java:2569)
	at org.apache.phoenix.query.ConnectionQueryServicesImpl$12.call(ConnectionQueryServicesImpl.java:2532)
	at org.apache.phoenix.util.PhoenixContextExecutor.call(PhoenixContextExecutor.java:76)
	at org.apache.phoenix.query.ConnectionQueryServicesImpl.init(ConnectionQueryServicesImpl.java:2532)
	at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:255)
	at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.createConnection(PhoenixEmbeddedDriver.java:150)
	at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:221)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:161)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:161)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:147)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:202)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
	at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)


2. 解决方法(1)

2.1 检查hbase与Phoenix安装目录下的hbase-site.xml文件

2.1.1 hbase的在conf目录下

在这里插入图片描述

2.1.2 phoenix的在bin目录下

在这里插入图片描述

2.1.3 把下面的代码块放在hbase-site.xml中,集群的每个hbase和phoenix的都要有一份

<property>
        <name>phoenix.schema.isNamespaceMappingEnabled</name>
        <value>true</value>
    </property>

    <property>
        <name>phoenix.schema.mapSystemTablesToNamespace</name>
        <value>true</value>
</property>

2.1.4 最后,idea里面也要有一份,在resources里面

在这里插入图片描述

3. 解决方法(2)

正常情况下这个时候已经解决了,但是我就是属于不正常的时候,还是会报错,这个时候尝试打印log日志来进行判断看哪个地方没输出了,然后慢慢判断。

3.1 尝试输出

        System.out.println("========== 开始连接 ============");
        connection = DriverManager.getConnection(GmallConfig.PHOENIX_SERVER);
        System.out.println("(((((((((((((((((((99999999999999999999999999999999");

运行之后发现只输出========== 开始连接 ============,很明显中间断了,然后寻找原因,发现phoenix和hbase的依赖用错了,下面粘个好的,然后就成功了。

        <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-client-hbase-2.4</artifactId>
            <version>5.1.2</version>
        </dependency>

4. 测试连接

 public static void main(String[] args) throws SQLException {
        Connection connection = DriverManager.getConnection(GmallConfig.PHOENIX_SERVER);
        System.out.println(connection);
        connection.close();
    }

运行结果:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用JDBC连接Phoenix时,可以通过连接URL或者通过Java代码设置一些配置参数。以下是一些常见的配置参数: 1. phoenix.query.timeoutMs:设置查询超时时间,单位为毫秒。 2. phoenix.query.keepAliveMs:设置查询保持活动状态的时间,单位为毫秒。 3. phoenix.query.maxGlobalMemoryPercentage:设置查询最大可使用的全局内存百分比。 4. phoenix.query.maxGlobalMemoryWaitMs:设置查询等待全局内存的最大时间,单位为毫秒。 5. phoenix.query.threadPoolSize:设置查询线程池的大小,用于并发执行查询操作。 6. phoenix.jdbc.autoCommit:设置是否自动提交事务,默认为true。 7. phoenix.jdbc.fetchSize:设置每次从服务器获取的行数,默认为0,表示使用默认大小。 8. phoenix.connection.autoCommit:设置是否自动提交事务,默认为true。 9. phoenix.mutate.batchSize:设置批量操作的大小,默认为1000。 10. phoenix.mutate.maxSize:设置批量操作的最大大小,默认为0,表示不限制大小。 可以通过在连接URL中添加参数来配置,例如: ``` jdbc:phoenix:localhost:2181:/hbase;phoenix.query.timeoutMs=5000;phoenix.connection.autoCommit=false ``` 或者通过Java代码设置参数,例如: ```java Properties props = new Properties(); props.setProperty("phoenix.query.timeoutMs", "5000"); props.setProperty("phoenix.connection.autoCommit", "false"); Connection conn = DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase", props); ``` 这些配置参数可以根据具体需求进行调整和优化,可以参考Phoenix官方文档或者相关资源了解更多可配置参数的详细信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值