mariadb-connector-r2dbc-usage

Guides writing reactive Java database code with MariaDB Connector/R2DBC.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-connector-r2dbc-usage-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-connector-r2dbc-usage
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/connectors/mariadb-connector-r2dbc-usage
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-connector-r2dbc-usage-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Reactive Java code written against MariaDB Connector/R2DBC often fails because JDBC idioms do not carry over: queries never execute without a subscription, results are consume-once, and errors arrive as onError signals rather than thrown exceptions. This Skill prevents those traps when writing or reviewing R2DBC application code. ## Core Features & Use Cases - Correct connection and query patterns: Covers the r2dbc:mariadb:// URL scheme, ConnectionFactories.get(url), positional ? (0-indexed) and named :name placeholders, and the rule that nothing runs until the returned Publisher is subscribed. - Reactive transaction and error handling: Explains beginTransaction()/commitTransaction() returning Mono<Void> that must be subscribed, autocommit defaulting to true, and errors surfacing as typed R2dbcException subclasses via onError. - Bulk operations and pooling: Shows Statement.add() for batched parameter sets, returnGeneratedValues() for auto-generated ids, fetchSize() for cursor-based fetching, and r2dbc-pool for connection pooling. - Use Case: When asked to write a reactive repository class that inserts rows into MariaDB and reads back generated ids, produce code that binds parameters, queues sets with add(), subscribes the transaction Monos, and maps the consume-once Result exactly once. ## Quick Start Write a reactive Java method using MariaDB Connector/R2DBC that inserts a row into a table and returns the generated id.

Frequently Asked Questions about mariadb-connector-r2dbc-usage

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I connect to MariaDB using R2DBC in Java?▼

Use the URL scheme r2dbc:mariadb://user:pw@host:port/db with ConnectionFactories.get(url), or build a MariadbConnectionConfiguration and pass it to new MariadbConnectionFactory(config). The registered driver id is mariadb.

Why does my R2DBC query not execute against MariaDB?▼

Statement.execute() returns a cold Flux of results, so nothing hits the wire until the Publisher is subscribed via subscribe(), block(), or a Reactor operator chain. Building the statement and calling execute() alone does nothing.

How do I bind parameters in MariaDB R2DBC statements?▼

Use positional ? placeholders bound by 0-based index with .bind(0, val), or named :name placeholders bound by name. For null values, use bindNull(index, Class) with an explicit SQL type since binding a plain null is invalid.

Does MariaDB Connector/R2DBC support connection pooling?▼

Pooling is not built into the driver. Add the r2dbc-pool dependency and wrap the MariadbConnectionFactory in a ConnectionPool built from ConnectionPoolConfiguration, borrowing connections with pool.create() and returning them with close().

How do transactions work in MariaDB R2DBC?▼

Autocommit defaults to true, so call setAutoCommit(false) or beginTransaction() first. beginTransaction(), commitTransaction(), and rollbackTransaction() each return Mono<Void> that is a no-op until subscribed, unlike JDBC's synchronous commit().

MariaDB Connector/R2DBC vs Connector/J: which should I use?▼

Connector/R2DBC is the reactive, non-blocking driver built on Reactor and Netty for reactive applications, while Connector/J is the blocking JDBC driver. Both are pure Java and independently versioned; JDBC idioms like try-with-resources ResultSet do not carry over.