0
点赞
收藏
分享

微信扫一扫

Failed to obtain JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerExceptio

兽怪海北 2022-05-05 阅读 140

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 'version' 不是可以识别的 内置函数名称。
### The error may exist in file [D:\software\Java\Project\cs\ceshi\astest\target\classes\mybatis\abc\abcMapper.xml]
### The error may involve com.abc.abcc.project.abc.mapper.abcMapper.get
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 'version' 不是可以识别的 内置函数名称。

这个问题卡了我好几天,试了更换jar包等众多解决方案,都未解决。之后看到这篇文章,顺利解决。

文章地址:DBCP针对不同数据库的validationQuery_Brent-CCNU的博客-CSDN博客_validationquery

原因:validationQuery不匹配

原配置:

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      # 主库数据源
      master:
        driverClassName: org.postgresql.Driver
        url: jdbc:postgresql://localhost:5432/test?currentSchema=test&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
        username: admin
        password: 123456
      slave:
        enabled: true
        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
        url: jdbc:sqlserver://localhost:1433;DatabaseName=wsd
        username: sa
        password: 123456
      # 初始连接数
      initialSize: 5
      # 最小连接池数量
      minIdle: 10
      # 最大连接池数量
      maxActive: 20
      # 配置获取连接等待超时的时间
      maxWait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      timeBetweenEvictionRunsMillis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      minEvictableIdleTimeMillis: 300000
      # 配置一个连接在池中最大生存的时间,单位是毫秒
      maxEvictableIdleTimeMillis: 900000
      # 配置检测连接是否有效
      validationQuery: select version()
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      webStatFilter:
        enabled: true
      statViewServlet:
        enabled: true
        # 设置白名单,不填则允许所有访问
        allow:
        url-pattern: /druid/*
        # 控制台管理用户名和密码
        login-username:
        login-password:
      filter:
        stat:
          enabled: true
          # 慢SQL记录
          log-slow-sql: true
          slow-sql-millis: 1000
          merge-sql: true
        wall:
          config:
            multi-statement-allow: true

解决办法:

只需要将validationQuery: select version() 改为 validationQuery: select 1,这样postgresql数据库也可以正常运行。

更改前:

更改后:

 希望对你有帮助。

举报

相关推荐

0 条评论