我想在JDBC/Hikari池中设置通用超时变量。
为此,我尝试了JDBC URL和Hikari配置中的变量,但似乎都不起作用。
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl("jdbc:mysql://*/*?wait_timeout=77&interactive_timeout=78");
hikariConfig.setUsername("*");
hikariConfig.setPassword("*");
hikariConfig.setConnectionTimeout(65 * 1000);
hikariConfig.setIdleTimeout(66 * 1000);
HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
Connection connection1 = hikariDataSource.getConnection();
Statement statement1 = connection1.createStatement();
ResultSet resultSet1 = null;
resultSet1 = statement1.executeQuery("show variables like '%timeout%'");
这里仍然得到默认值
while (resultSet1.next()) {
System.out.println(resultSet1.getString(1) + " " + resultSet1.getString(2));
}
明白了,我们可以通过
设置数据源属性hikariConfig.addDataSourceProperty()
裁判:https://www.baeldung.com/hikaricp