网上有不少人遇到过使用jdbc连接sqlserver出错的情况,错误信息为

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException:
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“SQL Server 未返回响应。连接已关闭。
ClientConnectionId:b441ca70-fe1b-4cde-9954-4f8251d62979”。
    at
com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)

解决方法有换驱动或者添加jar包。

如果你是用的较新的jdk,这些方法估计都没用。为了大家不走弯路,说说我的方法。

我这里的现象是使用jdk8u161没有问题,但是升级到171之后就都不行了。

网上各种方法无果后,想到既然是升级jdk导致的,查查jdk的Release Notes吧,在171的Release
Notes里果然找到一条关于ssl的安全性修复:

security-libs/javax.net.ssl

3DES Cipher Suites Disabled 

To improve the strength of SSL/TLS connections, 3DES cipher suites have been
disabled in SSL/TLS connections in the JDK via the jdk.tls.disabledAlgorithms
 Security Property.

再配合-Djavax.net.debug=ssl:handshake:verbose参数输出了ssl的调试信息,确定了sqlserver的ssl连接使用了3DES的算法。

修改jre\lib\security\java.security,删除jdk.tls.disabledAlgorithms中的3DES_EDE_CBC

重启服务,问题解决!

希望对大家有帮助。

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信