資料庫連線池-HikariCP-配置和使用
阿新 • • 發佈:2019-02-06
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);