HikariCP - 添加属性到 JDBC url
HikariCP - add properties to JDBC url
对于常规 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 属性)?
参见 Hikari 的 initialization, you can add property by using 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");
对于常规 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 属性)?
参见 Hikari 的 initialization, you can add property by using 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");