MariaDB Connector/R2DBC Guide

Quickstart guide for MariaDB Connector/R2DBC

MariaDB Connector/R2DBC allows Java developers to connect to MariaDB and MySQL databases using the Reactive Relational Database Connectivity (R2DBC) API. This enables non-blocking, asynchronous database operations, which are beneficial for building scalable and responsive applications.

1. Installation

Add the necessary dependency to your project's pom.xml (Maven) or build.gradle (Gradle) file. Choose the dependency based on the R2DBC Specification you are targeting.

a. For R2DBC 1.0.0 Specification (Recommended for new projects):

XML

<dependency>
    <groupId>org.mariadb</groupId>
    <artifactId>r2dbc-mariadb</artifactId>
    <version>1.2.x</version> </dependency>

Gradle

// Gradle
implementation 'org.mariadb:r2dbc-mariadb:1.2.x' // Use the latest stable version

b. For R2DBC 0.9.1 Specification (for compatibility):

XML

<dependency>
    <groupId>org.mariadb</groupId>
    <artifactId>r2dbc-mariadb-0.9.1-spec</artifactId>
    <version>1.2.x</version> </dependency>

Gradle

2. Basic Usage (Native R2DBC)

This example demonstrates how to establish a connection, execute a query, and process results using the reactive API.

Code snippet

Before Running:

  1. Replace your_username, your_password, your_database_name, and your_table_name with your actual MariaDB server details.

  2. Ensure you have a MariaDB server running and a database/table set up.

  3. Add reactor-core dependency if not already present, as R2DBC heavily relies on Project Reactor.

3. Connection Strings

MariaDB Connector/R2DBC supports a standard R2DBC URL format for connection:

r2dbc:mariadb://[username[:password]@]host[:port][/database][?option=value]

Example:

r2dbc:mariadb://user:pass@localhost:3306/mydb?useBatchMultiSend=true

4. Spring Data R2DBC

MariaDB Connector/R2DBC also integrates seamlessly with the Spring Data R2DBC framework, providing a higher-level abstraction for reactive database access, including repositories and entity mapping.

Further Resources:

This page is: Copyright © 2025 MariaDB. All rights reserved.

Last updated

Was this helpful?