ShardingJDBC 报错 Table or view does not exist

ShardingJDBC无法找到单表

依赖版本

<dependency>
	<groupId>org.apache.shardingsphere</groupId>
	<artifactId>shardingsphere-jdbc</artifactId>
	<exclusions>
		<exclusion>
			<groupId>org.apache.shardingsphere</groupId>
			<artifactId>shardingsphere-test-util</artifactId>
		</exclusion>
	</exclusions>
	<version>5.5.0</version>
</dependency>

出现异常

Caused by: org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException: Table or view 'xxxxxxx' does not exist.
	at org.apache.shardingsphere.infra.binder.segment.from.impl.SimpleTableSegmentBinder.lambda$checkTableExists$4(SimpleTableSegmentBinder.java:151) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions.checkState(ShardingSpherePreconditions.java:41) ~[shardingsphere-infra-exception-core-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.segment.from.impl.SimpleTableSegmentBinder.checkTableExists(SimpleTableSegmentBinder.java:148) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.segment.from.impl.SimpleTableSegmentBinder.bind(SimpleTableSegmentBinder.java:84) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinder.bind(TableSegmentBinder.java:55) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementBinder.lambda$bind$1(SelectStatementBinder.java:60) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at java.base/java.util.Optional.map(Optional.java:260) ~[na:na]
	at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementBinder.bind(SelectStatementBinder.java:60) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementBinder.bind(SelectStatementBinder.java:48) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bindDMLStatement(SQLBindEngine.java:82) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bind(SQLBindEngine.java:72) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bind(SQLBindEngine.java:63) ~[shardingsphere-infra-binder-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:207) ~[shardingsphere-jdbc-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:172) ~[shardingsphere-jdbc-5.5.0.jar:5.5.0]
	at org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection.prepareStatement(ShardingSphereConnection.java:94) ~[shardingsphere-jdbc-5.5.0.jar:5.5.0]
	at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:327) ~[HikariCP-5.0.1.jar:na]
	at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java) ~[HikariCP-5.0.1.jar:na]
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:88) ~[mybatis-3.5.16.jar:3.5.16]
	at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:90) ~[mybatis-3.5.16.jar:3.5.16]
	... 103 common frames omitted

解决方案

在ShardingJDBC的配置文件中添加以下配置:

# 规则配置
rules:
  - !SINGLE
    tables:
      # 加载全部单表
      - "ds0.*" 

ds0替换成你单表所在的数据源即可

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值