解决
**在配置文件中添加 **encrypt=true;trustServerCertificate=true;
就这样.
url: jdbc:sqlserver://xxxx;DatabaseName=xxxx;encrypt=true;trustServerCertificate=true; username: xxxx password: xxxx driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
前言
**今天在修改以前项目的时候发现了 Java 连接 SqlServer 出现了异常以前采用的 Maven 包是 **sqljdbc4
但是在我的仓库进行拉取的时候提示了 401
错误,然后我进入 mvnrepository
发现该包已经被转移了.
https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
**然后进行修改将 Maven 改为了 **mssql-jdbc
<dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>sqljdbc4</artifactId> <version>4.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc --> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>12.8.1.jre8</version> </dependency>
但是同样的配置文件就开始提示 SSL 异常
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption...
**然后经过查找发现默认开启了 **ssl
认证,只需要在 连接 jdbc
添加额外参数就可以解决 encrypt=true;trustServerCertificate=true;
url: jdbc:sqlserver://xxxx;DatabaseName=xxxx;encrypt=true;trustServerCertificate=true; username: xxxx password: xxxx driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
评论