Upgrade from MariaDB Connector/J 2.7 to 3.5
This page is part of MariaDB's Documentation.
The parent of this page is: MariaDB Connector/J
Topics on this page:
Overview
When upgrading from MariaDB Connector/J 2.7 to 3.5, application code must be updated to reflect changes in connector behavior.
MariaDB Connector/J 3.5 is fully compatible with MariaDB Connector/J 3.0, so upgrading from MariaDB Connector/J 3.0 to 3.5 should not require application changes.
Installation Changes
Enhanced Support For Features in Newer Java Versions
MariaDB Connector/J 3.5 uses Multi-Release JAR files (MRJAR), so it contains JAR files specific to different Java versions. This allows MariaDB Connector/J to continue supporting Java 8 while providing enhancements for newer versions of Java.
MariaDB Connector/J 3.5 also provides a Java 9 Platform Module System (JPMS) descriptor that provides the following information:
The module name
The module dependencies
The packages it makes available to other modules
The services it offers and consumes
Datasource Changes
MariaDB Connector/J 3.1 removes some deprecated methods from the MariaDbDataSource
class:
void setDatabaseName(String database)
void setPort(int port)
void setPortNumber(int port)
void setProperties(String properties)
void setServerName(String serverName)
void setUserName(String userName)
(butsetUser()
is still available.)
The setUrl(String url)
method can be used to configure the datasource without the above methods.
Easy To Use Logging
In MariaDB Connector/J 3.1, logging can be enabled at runtime. Connector/J uses the slf4j
API if it is installed. Otherwise, Connector/J uses the JDK logger / console.
Connector/J supports the following Java logging levels:
Log Levels | Description |
---|---|
| Logs connection errors |
| Logs SQL statements |
| Logs network exchanges |
New Authentication Plugin Option
MariaDB Connector/J 3.1 adds a new restrictedAuth
option to restrict authentication plugins.
The restrictedAuth
option can be set to a comma-separated list of client authentication plugins to allow. The following client authentication plugins are supported by default:
caching_sha2_password
For example, the following connection string only allows the mysql_native_password
and client_ed25519
client authentication plugins:
jdbc:mariadb://HOST/DATABASE?restrictedAuth=mysql_native_password,client_ed25519
New SSL/TLS Option
MariaDB Connector/J 3.1 adds a new sslMode
option to simplify the configuration of SSL/TLS.
The sslMode
option supports the following values:
Value | Description |
---|---|
| Do not use SSL/TLS (default) |
| Only use SSL/TLS for encryption. Do not perform certificate or hostname verification. This mode is not safe for production applications. |
| Use SSL/TLS for encryption and perform certificates verification, but do not perform hostname verification. |
| Use SSL/TLS for encryption, certificate verification, and hostname verification. |
MariaDB Connector/J 3.1 deprecates the following SSL/TLS options, but still supports them for compatibility:
disableSslHostnameVerification
trustServerCertificate
useSsl
New Socket Options
When MariaDB Connector/J 3.1 is used with Java 11 or later, some socket options can be configured:
Socket Option | Connector/J Option |
---|---|
|
|
|
|
|
|
These options only have an effect when MariaDB Connector/J 3.1 is used with Java 11 or later.
Connection Strings
jdbc:mariadb:
Scheme
MariaDB Connector/J 3.1 only accepts jdbc:mariadb:
as the protocol in connection strings by default. When both MariaDB Connector/J and the MySQL drivers are found in the class-path, using jdbc:mariadb:
as the protocol helps to ensure that Java chooses MariaDB Connector/J.
Connector/J still allows jdbc:mysql:
as the protocol in connection strings when the permitMysqlScheme
option is set. For example:
jdbc:mysql://HOST/DATABASE?permitMysqlScheme
Removed Support for Aurora
MariaDB Connector/J 3.1 removes Aurora-specific functions and options. Connection strings using the Aurora-specific HA mode are no longer supported:
jdbc:mariadb:aurora://HOST/DATABASE
Options
Changes to Default Values
Option | Old default value | New default value |
---|---|---|
|
|
|
|
|
|
New Options
Option | Description | Data Type | Default Value |
---|---|---|---|
| Accepts one of the two values | String |
|
| Enables the use of | Boolean |
|
| Sets a comma-separated list of client authentication plugins to allow. The following client authentication plugins are supported:
| String |
|
| Enables SSL/TLS in a specific mode. The following values are supported:
This new option replaces the deprecated options:
| String |
|
| Sets the | Integer |
|
| Sets the | Integer |
|
| Sets the | Integer |
|
| Enables transaction caching. If a failover occurs before a transaction is committed or rolled back, the transaction's cached statements are re-executed on the new primary server. Connector/J requires that applications only use idempotent queries. If the number of statements in the transaction cache exceeds | Boolean |
|
| Sets the number of statements that should be saved in the transaction cache when | Integer |
|
| Avoids unnecessary queries using local state if it is explicitly specified that only JDBC methods should be used, for example using the | Boolean |
|
Deprecated Options
Deprecated Option | Upgrade Guidance |
---|---|
| Use |
| Use |
| Use |
Removed Options
Removed Option | Upgrade Guidance |
---|---|
| In a Primary/Replica topology, the primary server must now be available. |
| Connections to replica servers are now ensured to be read-only. |
| Automatic reconnection can be enabled by setting a high availability (HA) mode in the connection string. |
| Prepared statements are always cached when using the binary protocol. |
| Callable statements are always cached when using the binary protocol. |
| The behavior now depends on which batch implementation is used. The batch implementation depends on the values of the |
| Network packet logging is now enabled using the |
| This option was only relevant for debugging, so no replacement is required. |
| In a Primary/Replica topology, the primary server must now be available. |
| The number of failover attempts is now configured by the |
| Connector/J now sets |
| This option is not supported by the default PKCS12 keystore type, so no replacement is required. |
| Connector/J now handles deny lists automatically. If all servers are denied, Connector/J will reconnect using the denied servers. |
| Logging is now enabled using the standard Java log levels. |
| Removed |
| Removed |
| Connection/J now sends passwords to the server encoded in UTF-8. |
| XA transactions can be used instead. |
| The cache is now limited to 8 KB. |
| SQL statement logging is now enabled using the |
| This option is made obsolete by the new failover implementation. |
| This option is made obsolete by the new batch implementation. |
| The time zone can be changed by setting the |
| Removed |
| |
| System variables can now be passed as arguments or set directly on the server. |
| Removed |
| Connector/J now reads all available data from the socket by default, so the buffer size is not configurable. |
| Removed |
| Connector/J now automatically enables this behavior by default. |
| The TrustStore can be set using the |
| The TrustStore can be set using the |
| The TrustStore can be set using the |
| This option is made obsolete by the new batch implementation. |
| This option is made obsolete by the new batch implementation. |
| Connector/J now expects all servers to support fractional seconds. |
| Connector/J now expects the current datetime implementation to be used. |
| Remove |
| Connector/J no longer automatically validates connections. Connection pools can be used to validate connections. |