2023.6.30//关于java链接SQLserver数据库报错:驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。
详情如下:
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”。 ClientConnectionId:32d195a6-03f5-4c43-b5f7-739c986ca205

网上的解决方案主要有:
修改java配置(java.security文件)
添加jar包到jre/lib/ext文件夹下
还有导入java的安全证书
通过修改URL来跳过安全验证
原URL代码:
String URL ="jdbc:sqlserver://"+ip
+"integratedSecurity=false;"
+"databaseName="+databaseName+";";
修改后URL代码:
String URL ="jdbc:sqlserver://"+ip
+"databaseName="+databaseName+";"
+"encrypt=true;"
+"trustServerCertificate=true;";