jast90 opened a new issue #14259:
URL: https://github.com/apache/shardingsphere/issues/14259


   ## Bug Report
   
   **For English only**, other languages will not accept.
   
   Before report a bug, make sure you have:
   
   - Searched open and closed [GitHub 
issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere 
Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more 
details. 
   If no response anymore and we cannot reproduce it on current information, we 
will **close it**.
   
   Please answer these questions before submitting your issue. Thanks!
   
   ### Which version of ShardingSphere did you use?
   5.0.0
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC 
   
   ### Expected behavior
   [            Preconditions.checkState(null == result || result == 
databaseType, "Database type inconsistent with '%s' and '%s'", result, 
databaseType);](https://github.com/apache/shardingsphere/blob/411a4062f429b74c7c47115e70a0ce56c65de537/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeRecognizer.java#L45)
   
   Always throwing exceptions
   
   ### Actual behavior
   
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   ```java
   public class HA {
   
       public static void main(String[] args) throws SQLException {
   
           // 配置真实数据源
           Map<String, DataSource> dataSourceMap = new HashMap<>();
   
           // 配置第 1 个数据源
           HikariDataSource dataSource1 = new HikariDataSource();
           dataSource1.setDriverClassName("com.mysql.jdbc.Driver");
           dataSource1.setJdbcUrl("jdbc:mysql://192.168.56.102:3306/ds0");
           dataSource1.setUsername("root");
           dataSource1.setPassword("123456");
           dataSourceMap.put("ds0", dataSource1);
   
           // 配置第 2 个数据源
           HikariDataSource dataSource2 = new HikariDataSource();
           dataSource2.setDriverClassName("com.mysql.jdbc.Driver");
           dataSource2.setJdbcUrl("jdbc:mysql://192.168.56.102:3307/ds1");
           dataSource2.setUsername("root");
           dataSource2.setPassword("123456");
           dataSourceMap.put("ds1", dataSource2);
           // 配置 t_order 表规则
           ShardingTableRuleConfiguration orderTableRuleConfig = new 
ShardingTableRuleConfiguration("t_order",
                   "ds${0..1}.t_order${0..1}");
           // 配置分库策略
           orderTableRuleConfig.setDatabaseShardingStrategy(
                   new StandardShardingStrategyConfiguration("user_id",
                           "dbShardingAlgorithm"));
           // 配置分表策略
           orderTableRuleConfig.setTableShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", "tableShardingAlgorithm"));
           // 配置分片规则
           ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
           shardingRuleConfig.getTables().add(orderTableRuleConfig);
   
           // 配置分库算法
           Properties dbShardingAlgorithmrProps = new Properties();
           dbShardingAlgorithmrProps.setProperty("algorithm-expression", 
"ds${user_id % 2}");
           
shardingRuleConfig.getShardingAlgorithms().put("dbShardingAlgorithm", new 
ShardingSphereAlgorithmConfiguration("INLINE", dbShardingAlgorithmrProps));
   
           // 配置分表算法
           Properties tableShardingAlgorithmrProps = new Properties();
           tableShardingAlgorithmrProps.setProperty("algorithm-expression", 
"t_order${order_id % 2}");
           
shardingRuleConfig.getShardingAlgorithms().put("tableShardingAlgorithm", new 
ShardingSphereAlgorithmConfiguration("INLINE", tableShardingAlgorithmrProps));
   
           Properties properties = new Properties();
           
properties.setProperty(ZookeeperPropertyKey.OPERATION_TIMEOUT_MILLISECONDS.getKey(),String.valueOf(10000));
           
properties.setProperty(ZookeeperPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(),String.valueOf(10000));
   
           ClusterPersistRepositoryConfiguration registryCenterConfig = new 
ClusterPersistRepositoryConfiguration(
                   "Zookeeper",
                   "governance-sharding-data-source",
                   "192.168.56.102:2181",
                   properties);
           // 配置 Cluster Config
           ModeConfiguration modeConfig = new ModeConfiguration("Cluster", 
registryCenterConfig, true);
   
           // 创建 ShardingSphereDataSource
           DataSource dataSource = 
ShardingSphereDataSourceFactory.createDataSource(modeConfig,dataSourceMap, 
Collections.singletonList(shardingRuleConfig),
                   new Properties());
   
           String sql = "SELECT i.* FROM t_order o JOIN t_order_item i ON 
o.order_id=i.order_id WHERE o.user_id=? AND o.order_id=?";
           try (
                   Connection conn = dataSource.getConnection();
                   PreparedStatement ps = conn.prepareStatement(sql)) {
               ps.setInt(1, 10);
               ps.setInt(2, 1000);
               try (ResultSet rs = ps.executeQuery()) {
                   while(rs.next()) {
   
                   }
               }
           }
   
       }
   }
   ```
   


-- 
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]


Reply via email to