Druid
import com.alibaba.druid.pool.DruidDataSource;
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(password);
dataSource.setLoginTimeout(timeout);
dataSource.setQueryTimeout(timeout);
dataSource.setInitialSize(10);
dataSource.setTestOnBorrow(true);
dataSource.setTimeBetweenEvictionRunsMillis(6000);
dataSource.setValidationQuery("select user()");
dataSource.setValidationQueryTimeout(3);
return dataSource;
Hikari
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
HikariConfig config = new HikariConfig();
config.setDriverClassName(driverClass);
config.setJdbcUrl(url);
config.setUsername(user);
config.setPassword(password);
config.setConnectionTimeout(timeout*1000);
config.setMaximumPoolSize(10);
config.setValidationTimeout(3000L);
config.setConnectionTestQuery("select user()");
config.setKeepaliveTime(30000L);
return new HikariDataSource(config);
dbcp2
import org.apache.commons.dbcp2.BasicDataSource;
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(driverClass);
ds.setUrl(url);
ds.setUsername(user);
ds.setPassword(password);
ds.setDefaultQueryTimeout(timeout);
ds.setInitialSize(10);
ds.setValidationQueryTimeout(3);
ds.setValidationQuery("select user()");
ds.setTimeBetweenEvictionRunsMillis(6000);
return ds;
文章来源地址https://www.toymoban.com/news/detail-603385.html
文章来源:https://www.toymoban.com/news/detail-603385.html
到了这里,关于springboot连接池Druid、Hikari、dbcp2配置dataSource的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!