美文网首页
常用数据库validationQuery语句

常用数据库validationQuery语句

作者: yichen_china | 来源:发表于2021-08-17 16:03 被阅读0次

    常用数据库validationQuery语句

    validationQuery是用来验证数据库连接的查询语句,这个查询语句必须是至少返回一条数据的SELECT语句。每种数据库都有各自的验证语句,下表中收集了几种常见数据库的validationQuery。

    DataBase validationQuery
    hsqldb select 1 from INFORMATION_SCHEMA.SYSTEM_USERS
    Oracle select 1 from dual
    DB2 select 1 from sysibm.sysdummy1
    MySql select 1
    Microsoft SqlServer select1
    postgresql select version()
    ingres select 1
    derby values 1
    H2 select 1
    

    配置文件

    spring:
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        dynamic:
          primary: master
          datasource:
            master:
              username: test
              password: test
              url: {url}
              driver-class-name: com.cloudera.impala.jdbc41.Driver
            secondary:
              username: test
              password: test
              url: {url}
              driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
            third:
              username: test
              password: test
              url: {url}
              driver-class-name: oracle.jdbc.driver.OracleDriver
              # 注意这儿
              druid:
                filters: stat,slf4j
                initial-size: 8
                max-active: 30
                max-pool-prepared-statement-per-connection-size: 20
                max-wait: 30000
                min-evictable-idle-time-millis: 300000
                min-idle: 8
                pool-prepared-statements: true
                test-while-idle: true
                test-on-borrow: false
                test-on-return: false
                time-between-eviction-runs-millis: 60000
                validation-query: 'select 1 from dual'
                useGlobalDataSourceStat: true
                stat:
                  log-slow-sql: true
                  merge-sql: true
                  slow-sql-millis: 10000
          druid:
            filters: stat,slf4j
            initial-size: 8
            max-active: 30
            max-pool-prepared-statement-per-connection-size: 20
            max-wait: 30000
            min-evictable-idle-time-millis: 300000
            min-idle: 8
            pool-prepared-statements: true
            test-while-idle: true
            test-on-borrow: false
            test-on-return: false
            time-between-eviction-runs-millis: 60000
            validation-query: 'select 1 '
            useGlobalDataSourceStat: true
            stat:
              log-slow-sql: true
              merge-sql: true
              slow-sql-millis: 10000
    

    相关文章

      网友评论

          本文标题:常用数据库validationQuery语句

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