数据库连接池-HikariCP-配置和使用

1. hikari.properties文件

jdbcUrl=jdbc:mysql://localhost:3306/test
username=test
password=123456
maximumPoolSize=30
minimumIdle=5
connectionTestQuery=SELECT 1
autoCommit=true
dataSource.cachePrepStmts=true
dataSource.prepStmtCacheSize=250
dataSource.prepStmtCacheSqlLimit=2048
dataSource.useServerPrepStmts=true
dataSource.useLocalSessionState=true
dataSource.useLocalTransactionState=true
dataSource.rewriteBatchedStatements=true
dataSource.cacheResultSetMetadata=true
dataSource.cacheServerConfiguration=true
dataSource.elideSetAutoCommits=true
dataSource.maintainTimeStats=false

2. 创建连接

HikariConfig config = new HikariConfig("src/hikari.properties");
System.out.println(config.getJdbcUrl());
System.out.println(config.getConnectionTimeout());
System.out.println(config.getMaximumPoolSize());
System.out.println(config.getMinimumIdle());
System.out.println(config.getUsername());
System.out.println(config.getPassword());

HikariDataSource ds = new HikariDataSource(config);

你可能感兴趣的:(MySql,Hikari,数据库连接池)