1. ModeConfiguration modeConfig = // Build running mode
  2. Map<String, DataSource> dataSourceMap = createDataSources();
  3. Collection<RuleConfiguration> ruleConfigs = ... // Build specific rules
  4. Properties props = ... // Build attribute configuration
  5. DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(databaseName, modeConfig, dataSourceMap, ruleConfigs, props);
  6. Map<String, DataSource> dataSourceMap = new HashMap<>();
  7. // Configure the 1st data source
  8. HikariDataSource dataSource1 = new HikariDataSource();
  9. dataSource1.setDriverClassName("com.mysql.jdbc.Driver");
  10. dataSource1.setJdbcUrl("jdbc:mysql://localhost:3306/ds_1");
  11. dataSource1.setUsername("root");
  12. dataSource1.setPassword("");
  13. // Configure the 2nd data source
  14. HikariDataSource dataSource2 = new HikariDataSource();
  15. dataSource2.setDriverClassName("com.mysql.jdbc.Driver");
  16. dataSource2.setJdbcUrl("jdbc:mysql://localhost:3306/ds_2");
  17. dataSource2.setUsername("root");
  18. dataSource2.setPassword("");