验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

SpringBoot怎么正确连接SqlServer

阅读:937 来源:乙速云 作者:代码code

SpringBoot怎么正确连接SqlServer

      一、正确的配置方式

      第一种:

      maven依赖

      
      
          net.sourceforge.jtds
          jtds
          1.3.1
      

      application.yml

      spring:
        datasource:
          driverClassName: net.sourceforge.jtds.jdbc.Driver
          url: jdbc:jtds:sqlserver://ip地址:端口号;database=数据库名字
          username: 账号
          password: 密码

      第二种: 

      maven依赖

      
          com.microsoft.sqlserver
          sqljdbc4
          4.0
      

      application.yml

      spring:
        datasource:
          driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
          url: jdbc:sqlserver://ip地址:端口号;database=数据库名字;encrypt=false
          username: 账号
          password: 密码

      二、常见问题

      1、驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接

      详细报错:

      nested exception is 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: 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS12]”。 ClientConnectionId:91ed7412-600a-4739-b527-1c083c3aa53e ### The error may exist in com/ruoyi/project/oldoa/mapper/NewsMapper.java (best guess) ### The error may involve com.ruoyi.project.oldoa.mapper.NewsMapper.selectList ### 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: 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS12]”。 ClientConnectionId:91ed7412-600a-4739-b527-1c083c3aa53e

       这个问题是因为没有选用好idea的jdk工具包,之前我一直使用的是Oracle OpenJDK,应该选用红框当中的JDK开发工具包就好了,配置方式如下:

      SpringBoot怎么正确连接SqlServer

      2、对象名 'DUAL' 无效

      详细报错:

      com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 ‘DUAL‘ 无效。

       你应该使用了RuoYi的框架,全局搜索一下

      validationQuery: SELECT 1 FROM DUAL

      改成

      validationQuery: SELECT 1

      因为SQL server 没有对象DUAL,也就是这个语句在SQL server下面是不能运行的,所以报错了。

    分享到:
    *特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
    相关文章
    {{ v.title }}
    {{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
    你可能感兴趣
    推荐阅读 更多>