ShardingSphere-JDBC
ShardingSphere-JDBC
Scenarios
There are two 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
Compiling ShardingSphere requires JDK 21 or later. Running applications that depend on ShardingSphere requires Java JRE 8 or later.
Procedure
- Rules configuration.
Please refer to User Manual for more details.
- Import Maven dependency
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc</artifactId>
<version>${latest.release.version}</version>
</dependency>Notice: Please change
${latest.release.version}to the actual version.
- 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- Take
spring bootas an example, editapplication.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.yamlFor details, see Spring Boot.