skip to Main Content

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)

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. It looks to me like a version mismatch issue. The setNetworkTimeout() was introduced in JDBC 4.1 and was not present in JDBC 4.0. From your stacktrace , it can be seen that :

    (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()
    

    this is what causing the issue. So , I suggest updating the mysql driver and any related dependencies to the latest version possible which should resolve your connection issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search