如何为Postgresql配置HikariCP? [英] How do I configure HikariCP for postgresql?

查看:1373
本文介绍了如何为Postgresql配置HikariCP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use HikariCP in postgresql and I can't find anywhere the configuration for postgresql.

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

Please point me to any example for postgresql with HikariCP or any configurations tutorial for the same.

我试图像下面那样使用它,但是它没有用,然后我意识到它是针对MySQL的。

I tried to use it like below but it didn't work and then I realized it was meant for 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;

    }


推荐答案

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);


这篇关于如何为Postgresql配置HikariCP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆