Retro Eye care Haitian Deep Dark Default

ShardingSphere-JDBC

Scenarios

There are four ways you can configure Apache ShardingSphere: Java and YAML. 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
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-jdbc-core</artifactId>
    <version>${latest.release.version}</version>
</dependency>

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

  1. Create YAML configuration file
# JDBC database name. In cluster mode, use this parameter to connect ShardingSphere-JDBC and ShardingSphere-Proxy.
# Default:logic_db
databaseName (?):

mode:

dataSources:

rules:
- !FOO_XXX
    ...
- !BAR_XXX
    ...

props:
  key_1: value_1
  key_2: value_2
  1. Take spring boot as an example, edit application.properties.
# Configuring DataSource Drivers
spring.datasource.driver-class-name=org.apache.shardingsphere.driver.ShardingSphereDriver
# Specify a YAML configuration file
spring.datasource.url=jdbc:shardingsphere:classpath:xxx.yaml

For details, see Spring Boot.