liruhui opened a new issue #15734:
URL: https://github.com/apache/shardingsphere/issues/15734
## Document Example
```java
example1: db${0..1}.t_order${0..1}
example2: db0.t_order$->{0..1},db1.t_order$->{2..4}
```
## Problem description
```java
In the example, the database name and table name are at least prefixed by
regular rules.
If the database name and table name are written randomly without rules and
prefixes,
how should they be written when using JavaAPI coding?
```
## For example
### 1:Database
```java
There are three databases aaa,bbb,ccc, There is table DDD in aaa, table EEE
in BBB and fff in CCC.
These three tables DDD, EEE and FFF are actually one table with different
names.
AAA
- DDD
BBB
- EEE
CCC
- FFF
````
### 2: CODE
```java
public static void main(String[] args) throws SQLException {
Map<String, DataSource> dataSourceMap =
Demo2DataSourceUtils.createDataSourceMap();
ShardingRuleConfiguration shardingRuleConfiguration = new
ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfiguration = new
ShardingTableRuleConfiguration("person","aaa.ddd,bbb.eee,ccc.fff");
Properties properties = new Properties();
properties.setProperty("sharding-count", "3");
shardingRuleConfiguration.getShardingAlgorithms().put("mod",new
ShardingSphereAlgorithmConfiguration("MOD",properties));
shardingRuleConfiguration.setDefaultTableShardingStrategy(new
StandardShardingStrategyConfiguration("id","mod"));
shardingRuleConfiguration.getTables().add(shardingTableRuleConfiguration);
DataSource dataSource =
ShardingSphereDataSourceFactory.createDataSource(dataSourceMap,
Collections.singleton(shardingRuleConfiguration), new Properties());
Connection connection = dataSource.getConnection();
connection.prepareStatement("insert into person
values(3,'yyyy','zzzzz')").execute();
connection.prepareStatement("insert into person
values(4,'yyyy','zzzzz')").execute();
connection.prepareStatement("insert into person
values(5,'yyyy','zzzzz')").execute();
}
```
### 3. Error Info
```java
Exception in thread "main" java.lang.IllegalStateException: Insert statement
does not support sharding table routing to multiple data nodes.
at
com.google.common.base.Preconditions.checkState(Preconditions.java:508)
at
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingInsertStatementValidator.postValidate(ShardingInsertStatementValidator.java:101)
at
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.lambda$createRouteContext$1(ShardingSQLRouter.java:57)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:57)
at
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:44)
at
org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:73)
at
org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:53)
at
org.apache.shardingsphere.infra.context.kernel.KernelProcessor.route(KernelProcessor.java:54)
at
org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:46)
at
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createExecutionContext(ShardingSpherePreparedStatement.java:431)
at
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:337)
at com.huige.cn.demo3.Demo3.main(Demo3.java:35)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]