本文主要介绍了Springboot如何正确连接SqlServer本文有一定的参考价值,感兴趣的同学可以借鉴一下
一、正确的配置方式
第一种:
maven依赖
1 2 3 4 5 6 |
|
application.yml
1 2 3 4 5 6 |
|
第二种:
maven依赖
1 2 3 4 5 |
|
application.yml
1 2 3 4 5 6 |
|
二、常见问题
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开发工具包就好了,配置方式如下:
2、对象名 'DUAL' 无效
详细报错:
com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 ‘DUAL‘ 无效。
你应该使用了RuoYi的框架,全局搜索一下
1 |
|
改成
1 |
|
因为SQL server 没有对象DUAL,也就是这个语句在SQL server下面是不能运行的,所以报错了。
以上就是我目前对于SpringBoot连接SqlServer的方式和常见的错误的汇总。