如何为 postgresql 配置 HikariCP?

Mba*_*uru 6 database postgresql connection-pooling hikaricp

我正在尝试在 postgresql 中使用 HikariCP,但在任何地方都找不到 postgresql 的配置。

请向我指出带有 HikariCP 的 postgresql 的任何示例或任何相同的配置教程。

我试着像下面那样使用它,但它没有用,然后我意识到它是为 MySQL 设计的

public static DataSource getDataSource()

    {

            if(datasource == null)

            {

                    HikariConfig config = new HikariConfig();


            config.setJdbcUrl("jdbc:mysql://localhost/test");

            config.setUsername("root");

            config.setPassword("password");



            config.setMaximumPoolSize(10);

            config.setAutoCommit(false);

            config.addDataSourceProperty("cachePrepStmts", "true");

            config.addDataSourceProperty("prepStmtCacheSize", "250");
            config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");



            datasource = new HikariDataSource(config);

            }

           return datasource;

    }
Run Code Online (Sandbox Code Playgroud)

use*_*900 6

您在HikariCP 配置wiki 页面中有示例

 Properties props = new Properties();

props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource");
props.setProperty("dataSource.user", "test");
props.setProperty("dataSource.password", "test");
props.setProperty("dataSource.databaseName", "mydb");
props.put("dataSource.logWriter", new PrintWriter(System.out));

HikariConfig config = new HikariConfig(props);
HikariDataSource ds = new HikariDataSource(config);
Run Code Online (Sandbox Code Playgroud)