What’s new in MariaDB Connector/J 3.0

Blog contributors: Diego Dupin and Ralf Gebhardt 

We are pleased to announce the general availability (GA) of MariaDB Connector/J 3.0. MariaDB Connector/J 3.0 is the newest version of MariaDB Connector/J for Java 8+, licensed under LGPL 2.1.

MariaDB Connector/J 3.0 is a complete rewrite to simplify the code, reduce the size of the connector and to gain better performance compared to MariaDB Connector/J 2.7.

MariaDB Connector/J 3.0 includes the following new enhancements:

  • Data exchange improvements
    • Optimistic Prepare
    • Faster network performance using the new MariaDB Server 10.6 feature to skip sending metadata
  • Faster connection creation
  • Transaction replay after a connector controlled failover
  • Enhanced support for features in newer java versions
    • New options `tcpKeepIdle`, `tcpKeepCount`, `tcpKeepInterval` for java 11+
    • Full JPMS module descriptor support
  • A new option `restrictedAuth`  enables restricting which authentication plugins can be used
  • Logging can be enabled at runtime
  • Simplified configuration for SSL/TLS


MariaDB Connector/J 3.0 provides significant performance improvements over MariaDB Connector/J 2.7.

The following real world TPCC benchmarks results compare MariaDB Connector/J 2.7.4 and 3.0.3. The first comparison is using the default setting, so client prepared statements are used. For the second comparison `useServerPrepStmts` is enabled to use server prepared statements.

Data Exchange Improvements

Optimistic Prepare

With Connector/J 3.0, when the connector is using the binary protocol by enabling the option `useServerPrepStmts`, any command is executed as a set of  PREPARE + EXECUTE commands. In contrast, Connector/J 2.7  requires the PREPARE result to be received before sending the EXECUTE command to the server.

With Connector/J 3.0, the connector will pipeline PREPARE and EXECUTE commands, being optimistic that the PREPARE command succeeds. (In case the PREPARE fails, the EXECUTE command won’t be executed). This avoids some network latency.


Faster network performance using MariaDB Server 10.6 metadata skip

MariaDB Server 10.6 provides a new feature to skip sending metadata when possible if the binary protocol is used.

When the option `useServerPrepStmts` is enabled, which means that the binary protocol is used, the Connector is taking advantage of this. For SQL commands, which return a resultset, the server will only send metadata once while receiving the data.

Metadata skip improves performance by reducing network traffic and eliminating redundant metadata parsing.

The following Connector internal JMH Benchmark results compare MariaDB Connector/J 2.7.4 and MariaDB Connector/J 3.0.3, selecting one row of a 100 INT column table:

Faster Connection Creation

When connecting to the server, MariaDB Connector/J 2.7 set some options via statements to the server to ensure session state.

Those options correspond to current server default behavior and to what JDBC expects (safe truncation, setting autocommit, etc.).

MariaDB Connector/J 3.0  avoids executing additional queries on connection creation, resulting in faster connection creation, as shown in the following benchmark.

Transaction Replay After Failover

MariaDB Connector/J provides its own failover functionality. A reconnection will be automatically done after a failover occurs, according to the high-availability configuration.

A new non-default option `transactionReplay` in MariaDB Connector/J 3.0 now allows caching a transaction, permitting the transaction to re-execute if a failover  occurs. The driver requires applications to use idempotent queries only (queries can be «replayable»).

If a failover occurs, the driver will recreate a new connection and replay the transaction from the cache. There are a few limitations (for example, if failover occurs during a commit, or if the transaction can’t be cached, because it contains more statements than the value of the new transactionReplaySize option).

Enhanced Support for Features in Newer Java Versions

MariaDB Connector/J 3.0 uses Multi-Release JARs (MRJAR), so it contains Java-version-specific JAR files. This means MariaDB Connector/J 3.0 still supports Java 8 while also providing enhancements for higher versions of Java.

With Java 9, MariaDB Connector/J 3.0 now also provides a Java 9 Platform Module System (JPMS) descriptor, providing information as:

  • the module name
  • module dependencies
  • the packages it makes available to other modules
  • the services it offers and consumes

With Java 11 some extensions are available for sockets like options TCP_KEEPIDLE, TCP_KEEPCOUNT and TCP_KEEPINTERVAL. These are now configurable via the new options `tcpKeepIdle`, `tcpKeepCount`, `tcpKeepInterval`. These options don’t have any effect if a Java version lower than 11 is used.

Authentication Plugin Restriction

A new option `restrictedAuth` allows restricting which authentication plugins can be used.

Example connection string: `jdbc:mariadb://localhost/db?restrictedAuth=mysql_native_password,client_ed25519`

This connection string only allows the authentication plugins mysql_native_password and client_ed25519.

Logging can be enabled at runtime

Logging can now be easily enabled at runtime. Logging will use slf4j if it is present and will otherwise fallback to using JDK logger / console. The following Java logging levels are supported:

  • INFO to log connection errors
  • DEBUG / FINE to additionally log SQL commands
  • TRACE / FINEST to additionally log network exchanges

Simplified configuration for SSL/TLS

A new option `sslMode` is available to simplify configuring SSL.

Possible value are :

disableNo ssl (default)
trustEncryption only (no certificate and hostname validation) (DEVELOPMENT ONLY)
verify-caEncryption, certificates validation, BUT no hostname verification
verify-fullStandard SSL use: Encryption, certificate validation and hostname validation

MariaDB Connector/J 3.0 still supports the old way via the options `useSsl`, `disableSslHostnameVerification`, `trustServerCertificate` for compatibility.

For More Information

Download/Install MariaDB Connector/J 3.0
Upgrade to MariaDB Connector/J 3.0