美文网首页
PostgreSql数据使用HikariDataSource数据

PostgreSql数据使用HikariDataSource数据

作者: Deer_Hunter | 来源:发表于2019-09-29 16:42 被阅读0次

环境:jdk 1.8  maven  postgreSql11

直接上代码:

maven引入jar包

compile"org.postgresql:postgresql:42.2.6"

注:如果jdk的版本低于1.7,使用低版本的jar包,42.2.6不支持低版本的j低于1.7的版本。

提供HikariDataSource默认使用静态块的方式提供。

package utils;

import com.zaxxer.hikari.HikariConfig;

import com.zaxxer.hikari.HikariDataSource;

public class DBUtil {

private static final HikariDataSourceDS;

static {

HikariConfig config =new HikariConfig();

config.setAutoCommit(true);

config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");

config.setUsername("postgresql");

config.setPassword("postgresql");

config.addDataSourceProperty("serverName", "localhost");

config.addDataSourceProperty("portNumber", 5432);

config.addDataSourceProperty("databaseName","test");

DS =new HikariDataSource(config);

}

public static void close() {

DS.close();

}

}

如果配置完成后如果报 如下错误可以参考我的另一篇日记:PostgreSql连接HikariDataSource提示SSL关闭处理

相关文章

网友评论

      本文标题:PostgreSql数据使用HikariDataSource数据

      本文链接:https://www.haomeiwen.com/subject/ojaeyctx.html