当前位置:   article > 正文

Spring Boot 中使用 Hikari连接各类数据源_hikaridatasource hive

hikaridatasource hive

Spring Boot 中使用 Hikari连接各类数据源


1,连接hive集群

HikariConfig中各属性设置
{
    "allowPoolSuspension": false,
    "autoCommit": true,
    "connectionTimeout": 10000,
    "driverClassName": "org.apache.hive.jdbc.HiveDriver",
    "idleTimeout": 30000,
    "initializationFailTimeout": 30000,
    "jdbcUrl": "jdbc:hive2://IP:port,IP:port,IP:port/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2",
    "leakDetectionThreshold": 0,
    "maxLifetime": 1800000,
    "maximumPoolSize": 15,
    "minimumIdle": 5,
    "password": "XXXXXX",
    "username": "XXXXX",
    "validationTimeout": 30000
}
获取连接
Connection=new HikariDataSource(hikariConfig).getConnection();
所需依赖(注意各依赖之间版本)
<!-- hive begin  -->
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>2.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-client</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey.contribs</groupId>
                    <artifactId>jersey-apache-client4</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.jetty.aggregate</groupId>
                    <artifactId>jetty-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.11</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>4.0.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.zookeeper</groupId>
                    <artifactId>zookeeper</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>4.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-client</artifactId>
            <version>4.0.1</version>
        </dependency>
<!-- hive end  -->
<!-- springboot 版本  -->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.9</version>
</parent>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81

2,连接postgresql

HikariConfig中各属性设置
{

    "connectionTimeout": 10000,
    "driverClassName": "org.postgresql.Driver",
    "idleTimeout": 30000,
    "initializationFailTimeout": 30000,
    "isolateInternalQueries": false,
    "jdbcUrl": "jdbc:postgresql://192.168.112.50:5433/dh",
    "leakDetectionThreshold": 0,
    "maxLifetime": 1800000,
    "maximumPoolSize": 15,
    "minimumIdle": 5,
    "password": "XXXXX",
    "poolName": "jdbc-hikari",
    "username": "XXXX",
    "validationTimeout": 30000
}
获取连接
Connection=new HikariDataSource(hikariConfig).getConnection();
所需依赖
<dependency>
       <groupId>org.postgresql</groupId>
       <artifactId>postgresql</artifactId>
       <version>42.1.1</version>
</dependency>
<!-- springboot 版本  -->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.9</version>
</parent>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

3,连接presto

HikariConfig中各属性设置
{

    "driverClassName": "io.prestosql.jdbc.PrestoDriver",
    "idleTimeout": 30000,
    "initializationFailTimeout": 30000,
    "jdbcUrl": "jdbc:presto://IP:port?SSL=true&SSLKeyStorePath=F:/key/presto.keystore&SSLKeyStorePassword=XXX",
    "leakDetectionThreshold": 0,
    "maxLifetime": 1800000,
    "maximumPoolSize": 15,
    "minimumIdle": 5,
    "password": "YYYYY",
    "readOnly": false,
    "registerMbeans": false,
    "username": "XXXX",
    "validationTimeout": 30000
}
获取连接
Connection=new HikariDataSource(hikariConfig).getConnection();
所需依赖
<dependency>
            <groupId>io.prestosql</groupId>
            <artifactId>presto-jdbc</artifactId>
            <version>338</version>
</dependency>
<!-- springboot 版本  -->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.9</version>
</parent>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

4,连接MySQL

HikariConfig中各属性设置
{
    "connectionTimeout": 10000,
    "driverClassName": "com.mysql.cj.jdbc.Driver",
    "idleTimeout": 30000,
    "initializationFailTimeout": 30000,
    "isolateInternalQueries": false,
    "jdbcUrl": "jdbc:mysql://192.168.112.50:3306/dhtest?useSSL=false",
    "leakDetectionThreshold": 0,
    "maxLifetime": 1800000,
    "maximumPoolSize": 15,
    "minimumIdle": 5,
    "password": "XXXXXX",
    "username": "XXXXX",
    "validationTimeout": 30000
}
获取连接
Connection=new HikariDataSource(hikariConfig).getConnection();
所需依赖
<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- springboot 版本  -->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.9</version>
</parent>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/160618
推荐阅读
相关标签
  

闽ICP备14008679号