Allow using MariaDB with JDBC MariaDB driver
The following discussion from !494 (merged) should be addressed:
-
@jkowalczyk started a discussion: (+2 comments) so mysql and not mariadb?
test done via .env file (docker-compose)
############################################
# By default without the .env file:
# ---> Database server: MySQL 5.7
# ---> JDBC driver: mysql
# DB_IMAGE="mysql:5.7"
# DB_DRIVER="mysql"
#
# ---> Database server: MariaDB 10.2
# ---> JDBC driver: mysql
# DB_IMAGE="mariadb:10.2"
# DB_DRIVER="mysql" # <---- Connection to database is not stable over time.
#
# ---> Database server: MariaDB 10.2
# ---> JDBC driver: mariadb # <--- not works /!\ @@@TODO
# DB_IMAGE="mariadb:10.2"
# DB_DRIVER="mariadb"
############################################
MariaDB + JDBC MariaDB = no connection established
INFO org.flywaydb.core.internal.license.VersionPrinter - Flyway Community Edition 6.0.8 by Redgate
INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1bqygw3ad14v7e52x18g2i|a307a8c, debugUnreturnedConnectionStackTraces -> true, description -> null, driverClass -> com.mysql.cj.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1bqygw3ad14v7e52x18g2i|a307a8c, idleConnectionTestPeriod -> 3600, initialPoolSize -> 5, jdbcUrl -> jdbc:mariadb://asqatasun-db_dev:3306/asqatasun, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 1000, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
WARN com.mchange.v2.resourcepool.BasicResourcePool - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@4647e89e
-- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
In my opinion, it is here
package org.asqatasun.persistence.config;
(...)
public abstract class PersistenceCommonConfig {
(...)
public static String MYSQL_DRIVER_CLASSNAME = "com.mysql.cj.jdbc.Driver";
public static String POSTGRES_DRIVER_CLASSNAME = "org.postgresql.Driver";
public static String HSQL_DRIVER_CLASSNAME = "org.hsqldb.jdbcDriver";
(...)
private static String getDriverClassNameFromUrl(String url) {
return getString(url, MYSQL_DRIVER_CLASSNAME, POSTGRES_DRIVER_CLASSNAME, HSQL_DRIVER_CLASSNAME);
}
see: https://mariadb.com/kb/en/about-mariadb-connector-j/
Please note that the driver class provided by MariaDB Connector/J
is notcom.mysql.jdbc.Driver
butorg.mariadb.jdbc.Driver
Edited by Matthieu FAURE