ShardingSphere-JDBC

1. Import Maven Dependency

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

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

2. Rules Configuration

ShardingSphere-JDBC can be configured by four methods, Java, YAML, Spring namespace and Spring boot starter. Developers can choose the suitable method according to different situations. Please refer to Configuration Manual for more details.

3. Create Data Source

Use ShardingSphereDataSourceFactory and rule configurations to create ShardingSphereDataSource, which implements DataSource interface of JDBC. It can be used for native JDBC or JPA, MyBatis and other ORM frameworks.

  1. DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, configurations, properties);