Search code examples
javamysqlmariadbhikaricp

Hikari Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)


I have an error when I create a Hikari connection, in a past have using mysql-connector but finally I decided use hikaricp.

This is the error:

[04:17:49] [Server thread/INFO]: HikariPool-1 - Starting...
[04:17:49] [Server thread/INFO]: HikariPool-1 - Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)
[04:17:49] [Server thread/INFO]: HikariPool-1 - Start completed.

My function:

    private static final HikariConfig config;
    private HikariDataSource dataSource;

    static {
        config = new HikariConfig();
    }

    public void open(){ 
        config.setJdbcUrl("jdbc:mysql://localhost:3306/"+ database);
        config.setUsername(user);
        config.setPassword(password);
        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        dataSource = new HikariDataSource(config);
    }

I have this pom.xml:

    <dependencies>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>3.4.5</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.divecrafts</groupId>
            <artifactId>spigot</artifactId>
            <version>1.8.8</version>
        </dependency>
    </dependencies>

My dedicated server is debian 9 using mariadb (latest version)


Solution

  • I fixed modifying my function:

    private Connection connection;
    
    public void open(){
            if (checkConnection()) return connection;
    
            final HikariDataSource ds = new HikariDataSource();
            ds.setMaximumPoolSize(20);
            ds.setDriverClassName("org.mariadb.jdbc.Driver");
            ds.setJdbcUrl(String.format("jdbc:mariadb://%s:%s/%s", hostname, port, database));
            ds.addDataSourceProperty("user", user);
            ds.addDataSourceProperty("password", password);
    
            connection = ds.getConnection();
            return connection;
    }
    

    And my pom.xml

        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.20</version>
            </dependency>
            <dependency>
                <groupId>org.mariadb.jdbc</groupId>
                <artifactId>mariadb-java-client</artifactId>
                <version>2.6.0</version>
            </dependency>
            <dependency>
                <groupId>com.zaxxer</groupId>
                <artifactId>HikariCP</artifactId>
                <version>3.4.5</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.12</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>net.divecrafts</groupId>
                <artifactId>spigot</artifactId>
                <version>1.8.8</version>
            </dependency>
        </dependencies>
    

    In summary, since I use mariadb I have added mariadb connector.