IDEA 连接SQL Server数据库出现错误 您所在的位置:网站首页 IDEA怎么连接sqlserver2008 IDEA 连接SQL Server数据库出现错误

IDEA 连接SQL Server数据库出现错误

2023-10-18 12:32| 来源: 网络整理| 查看: 265

版本:SQL Server2019,IDEA 2021.3,java 18.0.2,jdbc 11.2.0

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

 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targe

解决办法:

在要放入getConnection() 的url参数里加上

trustServerCertificate=true 即可。

代码:

package jdbc.util; import java.sql.*; public class BaseConnection { public static void main(String [] args) { String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; String dbURL="jdbc:sqlserver://localhost:1433;databaseName=StudentManagement;trustServerCertificate=true"; // 我的数据库名 StudentManagement String userName="sa"; // 填写你的用户名,我的是sa String userPwd="12345"; // 填写你的密码 try { Class.forName(driverName); Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd); System.out.println("连接数据库成功"); } catch(Exception ex) { ex.printStackTrace(); System.out.print("连接失败"); } } }

然后运行,就成功啦!!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有