flyway: Can't get connection with Java API

So i’m trying to setup flyway into my java Minecraft® plugin… I’ve managed to use the mvn plugin to run clean,baseline and migrate with the 2 database instance without issues Maria (lan) -> mysql 5.5 Mysql (localhost) -> mysql 8.0

But when I try to integrate the Java API in the project I can’t get any connection… Tried multiple flyway version, both urls and both datasource (ComboPooled)

Which version and edition of Flyway are you using?

Community 9.19.1

If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)

yes

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Java API, Maven plugin

Which database are you using? (Type & version)

Mariadb (mysql 5.5) or Mysql native 8.8

Which operating system are you using?

Windows pro 64b

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

Can’t get pass the fluent.load() to initiate connection:

What did you expect to see?

Establish a connection to DB

What did you see instead?

Unable to establish a connection to DB

  • Unsupported Database: MySQL 5.5 <-- With ComboPooledDatasource (used by a DaoManger and ‘c3po’)
  • Unsupported Database: MySQL 8.0 <-- With ComboPooledDatasource
  • Unable to obtain connection from database jdbc:mariadb <-- With url, user,pass
  • Unable to obtain connection from database jdbc:mysql <-- With url,user,pass

Pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.rvdprojects.whitelistje</groupId>
    <artifactId>Whitelist-Je</artifactId>
    <version>2023.3 ${maven.build.timestamp}</version>
    <packaging>jar</packaging>

    <name>Whitelist Je</name>

    <properties>
        <java.version>18</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
        <flyaway.configuration>flyaway.conf</flyaway.configuration>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.4.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>9.19.1</version>
                <configuration>
                    <configFiles>
                        <configFile>${flyaway.configuration}</configFile>
                    </configFiles>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

    <repositories>
        <repository>
            <id>spigotmc-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
        <repository>
            <id>dv8tion</id>
            <name>m2-dv8tion</name>
            <url>https://m2.dv8tion.net/releases</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.0.33</version>
        </dependency>
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20230227</version>
        </dependency>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.18.2-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.dv8tion</groupId>
            <artifactId>JDA</artifactId>
            <version>4.4.1_353</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.18.4</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>3.18.4</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>3.18.4</version>
        </dependency>
        <dependency>
            <groupId>io.sentry</groupId>
            <artifactId>sentry</artifactId>
            <version>6.22.0</version>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>9.19.1</version>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-mysql</artifactId>
            <version>9.19.1</version>
        </dependency>
        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>3.1.4</version>
        </dependency>        
    </dependencies>
</project>

Source for ComboPolledDatasource

package helpers;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import configs.ConfigManager;

public class DbPoolFactory {

    public static final ComboPooledDataSource getMysqlPool(ConfigManager configs) throws Exception {

        // JDBC Driver Name & Database URL
        final String JDBC_DRIVER = "com.mysql.jdbc.Driver";

        // JDBC Driver Name & Database URL
        final String JDBC_URL = configs.get("mysqlJdbcUrl") + 
            "?connectionAttributes=program_name:WhiteList-Je";

        final Integer JDBC_MAX_ACTIVE = Integer.parseInt(configs.get("mysqlMaxConnection", "15"));
        final Integer JDBC_MAX_IDLE = Integer.parseInt(configs.get("mysqlMaxConnectionIDLE", "5"));

        final String JDBC_USER = configs.get("mysqlUser");
        final String JDBC_PASS = configs.get("mysqlPass");

        Class.forName(JDBC_DRIVER);

        // Creates an Instance of GenericObjectPool That Holds Our Pool of Connections
        // Object!
        ComboPooledDataSource ds = new ComboPooledDataSource();
        ds.setDriverClass(JDBC_DRIVER);
        ds.setJdbcUrl(JDBC_URL);
        ds.setUser(JDBC_USER);
        ds.setPassword(JDBC_PASS);
        ds.setMinPoolSize(JDBC_MAX_IDLE);
        ds.setMaxPoolSize(JDBC_MAX_ACTIVE);
        ds.setTestConnectionOnCheckin(true);
        ds.setTestConnectionOnCheckout(true);
        ds.setDescription("Pool for Wje Mc®");
        ds.setDataSourceName("Wje-plugin");


        return ds;
    }
}

MIGRATOR CLASS: //FIXME:

package db;

import java.util.logging.Logger;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.configuration.FluentConfiguration;

import configs.ConfigManager;
import dao.DaoManager;
import io.sentry.ISpan;
import io.sentry.SpanStatus;
import main.WhitelistJe;
import services.sentry.SentryService;

public class Migrator {
    private WhitelistJe plugin;
    private Flyway flyway;
    private Logger logger;

    /**
     * @param plugin
     */
    public Migrator(WhitelistJe plugin) {
        try {
            ISpan process = plugin.getSentryService().findWithuniqueName("onEnable")
                    .startChild("Migrator");

            this.plugin = plugin;
            this.logger = Logger.getLogger("WJE:" + getClass().getSimpleName());

            final ConfigManager configs = this.plugin.getConfigManager();
            
            final String JDBC_USER = configs.get("mysqlUser");
            final String JDBC_PASS = configs.get("mysqlPass");
            final String JDBC_URL = configs.get("mysqlJdbcUrl");
            final String M_JDBC_URL = configs.get("mariaJdbcUrl");
            
            FluentConfiguration flywayConfigs = Flyway.configure()
            .dataSource(DaoManager.getDatasource())
            .locations("classpath:db/migration");

            this.flyway = new Flyway(flywayConfigs);
            flyway.migrate();

            process.setStatus(SpanStatus.OK);
            process.finish();
        } catch (Exception e) {
            SentryService.captureEx(e);
        }
    }
}

Where the class is instanciated: *Minecraft server ‘load’

    @Override
    public final void onEnable() {
        ITransaction transaction = Sentry.startTransaction("onEnable", "configurePlugin");
        final StringBuilder sb = new StringBuilder();

        try {
            this.configManager = new ConfigManager();
            logger.info("LOADED: ConfigManager");
            
            LOCALES = new LocalManager(this);
            logger.info("LOADED: LocalManager");
            
            sentryService = new SentryService(this);
            transaction = sentryService.createTx("onEnable", "configurePlugin");
            logger.info("LOADED: SentryService");
            
            daoManager = new DaoManager(this);
            logger.info("LOADED: DaoManager");

            migrator = new Migrator(this);
            logger.info("LOADED: Migrator");
          
        } catch (Exception e) {
                ............
        }

        transaction.setStatus(SpanStatus.OK);
        transaction.finish();
    }

About this issue

Most upvoted comments

Could you share a full print out log of the failed execution ?