public static void main(String [] args){
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=example_ex;";
String userName="sa";
String userPwd="root";
try{
Class.forName(driverName);
System.out.println("加载驱动成功!");
}catch(Exception e){
e.printStackTrace();
System.out.println("加载驱动失败!");
}
try{
Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("连接数据库成功!");
}catch(Exception e){
e.printStackTrace();
System.out.print("SQL Server连接失败!");
}
}
}
com.microsoft.sqlserver.jdbc.SQLServerException: 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”。 ClientConnectionId:e860a702-ef55-4ea3-a2e7-cd110eaff3ad
端口不一样,协议不一样,sql也不完全一样
你要拿mysql的类库去连sqlserver
dbUrl换成这个jdbc:sqlserver://localhost:1433;DatabaseName=example_ex;useSSL=false;