ShardingSphere-JDBC Supports all JDBC drivers and database connection pools.

Example

In this example, the database driver is MySQL, and connection pool is HikariCP, which can be replaced with other database drivers and connection pools.

  1. Map<String, DataSource> dataSourceMap = new HashMap<>();
  2. // Configure the 1st data source
  3. HikariDataSource dataSource1 = new HikariDataSource();
  4. dataSource1.setDriverClassName("com.mysql.jdbc.Driver");
  5. dataSource1.setJdbcUrl("jdbc:mysql://localhost:3306/ds_1");
  6. dataSource1.setUsername("root");
  7. dataSource1.setPassword("");
  8. dataSourceMap.put("ds_1", dataSource1);
  9. // Configure the 2nd data source
  10. HikariDataSource dataSource2 = new HikariDataSource();
  11. dataSource2.setDriverClassName("com.mysql.jdbc.Driver");
  12. dataSource2.setJdbcUrl("jdbc:mysql://localhost:3306/ds_2");
  13. dataSource2.setUsername("root");
  14. dataSource2.setPassword("");
  15. dataSourceMap.put("ds_2", dataSource2);
  16. // Configure other data sources
  17. ...