Hikari 驱动程序不支持 get/set 网络连接超时。 (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()我)
Hikari Driver does not support get/set network timeout for connections. (com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()I)
创建 Hikari 连接时出现错误,过去使用 mysql-connector 但最后我决定使用 hikaricp。
这是错误:
[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.
我的函数:
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);
}
我有这个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>
我的专用服务器是 debian 9 使用 mariadb(最新版本)
在我看来像是版本不匹配的问题。 setNetworkTimeout()
在 JDBC 4.1
中引入,在 JDBC 4.0
中不存在。从您的堆栈跟踪中可以看出:
(com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()
这就是导致问题的原因。因此,我建议将 mysql 驱动程序和任何相关依赖项更新到可能的最新版本,这应该可以解决您的连接问题。
我修改了我的函数:
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;
}
还有我的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>
总而言之,由于我使用了 mariadb,所以我添加了 mariadb 连接器。
创建 Hikari 连接时出现错误,过去使用 mysql-connector 但最后我决定使用 hikaricp。
这是错误:
[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.
我的函数:
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);
}
我有这个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>
我的专用服务器是 debian 9 使用 mariadb(最新版本)
在我看来像是版本不匹配的问题。 setNetworkTimeout()
在 JDBC 4.1
中引入,在 JDBC 4.0
中不存在。从您的堆栈跟踪中可以看出:
(com.mysql.jdbc.JDBC4Connection.getNetworkTimeout()
这就是导致问题的原因。因此,我建议将 mysql 驱动程序和任何相关依赖项更新到可能的最新版本,这应该可以解决您的连接问题。
我修改了我的函数:
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;
}
还有我的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>
总而言之,由于我使用了 mariadb,所以我添加了 mariadb 连接器。