HikariCP-向JDBC URL添加属性

时间:2018-07-08 14:07:02

标签: java jdbc hikaricp

对于常规JDBC连接,您可以将属性添加到DriverManager:

url = "jdbc:postgresql://host:port/db?user=user&password=pass";

Properties props = new Properties();

DriverManager.getConnection(url,props);

对于HikariCP,它有hikariConfig.setJdbcUrl(url);

如何为JDBC连接添加属性(不是HikariCP属性)?

1 个答案:

答案 0 :(得分:1)

请参见Hikari的initialization,您可以使用config.addDataSourceProperty方法添加属性:

HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://localhost:3306/simpsons");
config.setUsername("bart");
config.setPassword("51mp50n");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");