ShardingSphere-JDBC

Scenarios

There are four ways you can configure Apache ShardingSphere: Java, YAML, Spring namespace and Spring boot starter. Developers can choose the preferred method according to their requirements.

Limitations

Currently only Java language is supported.

Requirements

The development environment requires Java JRE 8 or later.

Procedure

  1. Rules configuration.

Please refer to User Manual for more details.

  1. Import Maven dependency
  1. <dependency>
  2. <groupId>org.apache.shardingsphere</groupId>
  3. <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
  4. <version>${latest.release.version}</version>
  5. </dependency>

Notice: Please change ${latest.release.version} to the actual version.

  1. Edit application.yml.
  1. spring:
  2. shardingsphere:
  3. datasource:
  4. names: ds_0, ds_1
  5. ds_0:
  6. type: com.zaxxer.hikari.HikariDataSource
  7. driverClassName: com.mysql.cj.jdbc.Driver
  8. jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
  9. username: root
  10. password:
  11. ds_1:
  12. type: com.zaxxer.hikari.HikariDataSource
  13. driverClassName: com.mysql.cj.jdbc.Driver
  14. jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
  15. username: root
  16. password:
  17. rules:
  18. sharding:
  19. tables:
  20. ...